summaryrefslogtreecommitdiff
path: root/src/shared/unit-name.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-07-10 17:03:11 +0200
committerLennart Poettering <lennart@poettering.net>2012-07-10 17:07:32 +0200
commit5f73969991fa765f2826975c0fc5e47438b5e9ea (patch)
treebd9c5e438951fe0a584f1ad1b88897ceebe8a60a /src/shared/unit-name.c
parent0bf07cb5e4db097fcc25784b491fc4311d20fff2 (diff)
unit-name: remove unit_name_is_valid_no_type() and move unit_name_is_valid() to unit-name.h
Diffstat (limited to 'src/shared/unit-name.c')
-rw-r--r--src/shared/unit-name.c19
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);
+}