X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Funit-name.c;h=debf2b265333c0bbcb66f2a014275e09afcdf2ec;hp=dbaa4a7b12c3acdf5b02b323e236477e0336d8cb;hb=2633eb8317623138f585957fcf8337a99fb1528f;hpb=9fff8a1f165eb401f5411f96c755bb7704fdaa81 diff --git a/src/unit-name.c b/src/unit-name.c index dbaa4a7b1..debf2b265 100644 --- a/src/unit-name.c +++ b/src/unit-name.c @@ -272,13 +272,13 @@ char *unit_name_unescape(const char *f) { else if (*f == '\\') { int a, b; - if ((a = unhexchar(f[1])) < 0 || - (b = unhexchar(f[2])) < 0) { - /* Invalid escape code, let's take it literal then */ + if (f[1] != 'x' || (a = unhexchar(f[2])) < 0 || + (b = unhexchar(f[3])) < 0) { + /* Invalid escape code, let's take it literal then */ *(t++) = '\\'; } else { *(t++) = (char) ((a << 4) | b); - f += 2; + f += 3; } } else *(t++) = *f; @@ -427,3 +427,26 @@ char *unit_name_to_path(const char *name) { return e; } + +char *unit_name_path_unescape(const char *f) { + char *e; + + assert(f); + + if (!(e = unit_name_unescape(f))) + return NULL; + + if (e[0] != '/') { + char *w; + + w = strappend("/", e); + free(e); + + if (!w) + return NULL; + + e = w; + } + + return e; +}