From 5f73969991fa765f2826975c0fc5e47438b5e9ea Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 10 Jul 2012 17:03:11 +0200 Subject: unit-name: remove unit_name_is_valid_no_type() and move unit_name_is_valid() to unit-name.h --- src/shared/unit-name.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/shared/unit-name.c') 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); +} -- cgit v1.2.3-54-g00ecf