summaryrefslogtreecommitdiffstats
path: root/src/shared/volatile-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-05-22 12:09:59 +0200
committerLennart Poettering <lennart@poettering.net>2018-05-22 13:14:18 +0200
commit081a0c7256136e949a4a27fa965d40368cb8e5ce (patch)
tree7685487928b11f496d8f9a5954a23bd37b205809 /src/shared/volatile-util.c
parentcoredumpctl: always output proper english sentence (diff)
downloadsystemd-081a0c7256136e949a4a27fa965d40368cb8e5ce.tar.xz
systemd-081a0c7256136e949a4a27fa965d40368cb8e5ce.zip
volatile-mode: use the usual string table macros for implementing volatile_mode_from_string()
Let's shorten our code a bit, and also add the matching _to_string() call.
Diffstat (limited to 'src/shared/volatile-util.c')
-rw-r--r--src/shared/volatile-util.c27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/shared/volatile-util.c b/src/shared/volatile-util.c
index d70d5856d3..a20f0b43f4 100644
--- a/src/shared/volatile-util.c
+++ b/src/shared/volatile-util.c
@@ -11,27 +11,10 @@
#include "macro.h"
#include "parse-util.h"
#include "proc-cmdline.h"
+#include "string-table.h"
#include "string-util.h"
#include "volatile-util.h"
-VolatileMode volatile_mode_from_string(const char *s) {
- int b;
-
- if (isempty(s))
- return _VOLATILE_MODE_INVALID;
-
- b = parse_boolean(s);
- if (b > 0)
- return VOLATILE_YES;
- if (b == 0)
- return VOLATILE_NO;
-
- if (streq(s, "state"))
- return VOLATILE_STATE;
-
- return _VOLATILE_MODE_INVALID;
-}
-
int query_volatile_mode(VolatileMode *ret) {
_cleanup_free_ char *mode = NULL;
VolatileMode m = VOLATILE_NO;
@@ -56,3 +39,11 @@ finish:
*ret = m;
return r;
}
+
+static const char* const volatile_mode_table[_VOLATILE_MODE_MAX] = {
+ [VOLATILE_NO] = "no",
+ [VOLATILE_YES] = "yes",
+ [VOLATILE_STATE] = "state",
+};
+
+DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(volatile_mode, VolatileMode, VOLATILE_YES);