aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2015-12-10 17:55:06 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2015-12-10 17:55:06 +0100
commit38cccfcf9cb02b5a470dd4de31c528e1d106a100 (patch)
tree3bce0455549cae3ba7f8f05d48e44a398bb87108
parent34fc3d39e4038b72513db2fc35077251f1f15d01 (diff)
allow to query path having heading /
Change-Id: I9be22c09557f426f271310fac4b1cdd5000e0161
-rw-r--r--src/wgt.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/wgt.c b/src/wgt.c
index db59091..9c3cd6e 100644
--- a/src/wgt.c
+++ b/src/wgt.c
@@ -71,6 +71,13 @@ static int validsubpath(const char *subpath)
return l >= 0;
}
+static const char *normalsubpath(const char *subpath)
+{
+ while(*subpath == '/')
+ subpath++;
+ return validsubpath(subpath) ? subpath : NULL;
+}
+
struct wgt *wgt_create()
{
struct wgt *wgt = malloc(sizeof * wgt);
@@ -150,7 +157,9 @@ int wgt_has(struct wgt *wgt, const char *filename)
{
assert(wgt);
assert(wgt_is_connected(wgt));
- if (!validsubpath(filename)) {
+
+ filename = normalsubpath(filename);
+ if (!filename) {
errno = EINVAL;
return -1;
}
@@ -161,7 +170,8 @@ int wgt_open_read(struct wgt *wgt, const char *filename)
{
assert(wgt);
assert(wgt_is_connected(wgt));
- if (!validsubpath(filename)) {
+ filename = normalsubpath(filename);
+ if (!filename) {
errno = EINVAL;
return -1;
}
@@ -229,7 +239,8 @@ static const char *localize(struct wgt *wgt, const char *filename, char path[PAT
{
int i;
- if (!validsubpath(filename)) {
+ filename = normalsubpath(filename);
+ if (!filename) {
errno = EINVAL;
return NULL;
}