* suffix and makes a nice string suitable as unit name of it,
* escaping all weird chars on the way.
*
- * / becomes ., and all chars not alloweed in a unit name get
+ * / becomes ., and all chars not allowed in a unit name get
* escaped as \xFF, including \ and ., of course. This
* escaping is hence reversible.
*
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;
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;
+}