diff options
Diffstat (limited to 'src/shared/unit-name.c')
-rw-r--r-- | src/shared/unit-name.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c index 88ca0b8f2c..06bbfacb00 100644 --- a/src/shared/unit-name.c +++ b/src/shared/unit-name.c @@ -506,6 +506,36 @@ char *unit_name_mangle(const char *name) { return r; } +char *snapshot_name_mangle(const char *name) { + char *r, *t; + const char *f; + + assert(name); + + /* Similar to unit_name_mangle(), but is called when we know + * that this is about snapshot units. */ + + r = new(char, strlen(name) * 4 + 1 + sizeof(".snapshot")-1); + if (!r) + return NULL; + + for (f = name, t = r; *f; f++) { + if (*f == '/') + *(t++) = '-'; + else if (!strchr(VALID_CHARS, *f)) + t = do_escape_char(*f, t); + else + *(t++) = *f; + } + + if (!endswith(name, ".snapshot")) + strcpy(t, ".snapshot"); + else + *t = 0; + + return r; +} + UnitType unit_name_to_type(const char *n) { const char *e; |