X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=util.c;h=c7b2ca8516fa663f0d65158850e29088241dd143;hp=f752a248ec6e014a5f662d08450a79187f26ec10;hb=acbb02252a38214ecba3aa8a5c9b3669f9c9317e;hpb=87f0e418cf2c58b3201d06a60e3696ec672d2662 diff --git a/util.c b/util.c index f752a248e..c7b2ca851 100644 --- a/util.c +++ b/util.c @@ -253,7 +253,7 @@ char *split_quoted(const char *c, size_t *l, char **state) { (*state)++; } else if (*current == '\"') { current ++; - *l = strcspn(current+1, "\""); + *l = strcspn(current, "\""); *state = current+*l; if (**state == '\"') @@ -443,3 +443,28 @@ char *file_name_from_path(const char *p) { return (char*) p; } + +bool path_is_absolute(const char *p) { + assert(p); + + return p[0] == '/'; +} + +bool is_path(const char *p) { + + return !!strchr(p, '/'); +} + +char *path_make_absolute(const char *p, const char *prefix) { + char *r; + + assert(p); + + if (path_is_absolute(p) || !prefix) + return strdup(p); + + if (asprintf(&r, "%s/%s", prefix, p) < 0) + return NULL; + + return r; +}