X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=unit.c;h=39c9e5e7e83d86156ca6440a67bbf8ddae706c97;hb=c9dae904f3a07ae563bd58fb2b39529c1f108915;hp=980c3711eb147d60075c416643d54e74bd57f69a;hpb=6be1e7d538e12f4e5c79c1271dba90e66726d8fd;p=elogind.git diff --git a/unit.c b/unit.c index 980c3711e..39c9e5e7e 100644 --- a/unit.c +++ b/unit.c @@ -1001,10 +1001,10 @@ int set_unit_path(const char *p) { return 0; } -char *unit_name_escape_path(const char *prefix, const char *path, const char *suffix) { +char *unit_name_escape_path(const char *path, const char *suffix) { char *r, *t; const char *f; - size_t a, b, c; + size_t a, b; assert(path); @@ -1017,22 +1017,16 @@ char *unit_name_escape_path(const char *prefix, const char *path, const char *su * escaping is hence reversible. */ - if (!prefix) - prefix = ""; - if (!suffix) suffix = ""; - a = strlen(prefix); - b = strlen(path); - c = strlen(suffix); + a = strlen(path); + b = strlen(suffix); - if (!(r = new(char, a+b*4+c+1))) + if (!(r = new(char, a*4+b+1))) return NULL; - memcpy(r, prefix, a); - - for (f = path, t = r+a; *f; f++) { + for (f = path, t = r; *f; f++) { if (*f == '/') *(t++) = '.'; else if (*f == '.' || *f == '\\' || !strchr(VALID_CHARS, *f)) { @@ -1044,7 +1038,7 @@ char *unit_name_escape_path(const char *prefix, const char *path, const char *su *(t++) = *f; } - memcpy(t, suffix, c+1); + memcpy(t, suffix, b+1); return r; }