-char *unit_name_build_escape(const char *prefix, const char *instance, const char *suffix) {
- char *r, *t;
- size_t a, b, c;
-
- assert(prefix);
- assert(suffix);
-
- /* Takes a arbitrary string for prefix and instance plus a
- * suffix and makes a nice string suitable as unit name of it,
- * escaping all weird chars on the way.
- *
- * / becomes -, and all chars not allowed in a unit name get
- * escaped as \xFF, including \ and -, of course. This
- * escaping is hence reversible.
- *
- * This is primarily useful to make nice unit names from
- * strings, but is actually useful for any kind of string.
- */
-
- a = strlen(prefix);
- c = strlen(suffix);
-
- if (instance) {
- b = strlen(instance);
-
- if (!(r = new(char, a*4 + 1 + b*4 + c + 1)))
- return NULL;
-
- t = do_escape(prefix, r);
- *(t++) = '@';
- t = do_escape(instance, t);
- } else {
-
- if (!(r = new(char, a*4 + c + 1)))
- return NULL;
-
- t = do_escape(prefix, r);
- }
-
- strcpy(t, suffix);
- return r;
-}
-