diff options
Diffstat (limited to 'src/shared/unit-name.c')
-rw-r--r-- | src/shared/unit-name.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c index 67a760ace6..cbe0b05377 100644 --- a/src/shared/unit-name.c +++ b/src/shared/unit-name.c @@ -48,7 +48,7 @@ static const char* const unit_type_table[_UNIT_TYPE_MAX] = { DEFINE_STRING_TABLE_LOOKUP(unit_type, UnitType); -bool unit_name_is_valid_no_type(const char *n, bool template_ok) { +bool unit_name_is_valid(const char *n, bool template_ok) { const char *e, *i, *at; /* Valid formats: @@ -66,6 +66,9 @@ bool unit_name_is_valid_no_type(const char *n, bool template_ok) { if (!e || e == n) return false; + if (unit_type_from_string(e + 1) < 0) + return false; + for (i = n, at = NULL; i < e; i++) { if (*i == '@' && !at) @@ -169,7 +172,7 @@ char *unit_name_change_suffix(const char *n, const char *suffix) { size_t a, b; assert(n); - assert(unit_name_is_valid_no_type(n, true)); + assert(unit_name_is_valid(n, true)); assert(suffix); assert_se(e = strrchr(n, '.')); @@ -485,3 +488,15 @@ char *unit_name_mangle(const char *name) { return r; } + +UnitType unit_name_to_type(const char *n) { + const char *e; + + assert(n); + + e = strrchr(n, '.'); + if (!e) + return _UNIT_TYPE_INVALID; + + return unit_type_from_string(e + 1); +} |