summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/shared/volatile-util.c27
-rw-r--r--src/shared/volatile-util.h1
2 files changed, 10 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);
diff --git a/src/shared/volatile-util.h b/src/shared/volatile-util.h
index b275bff176..4312c97a99 100644
--- a/src/shared/volatile-util.h
+++ b/src/shared/volatile-util.h
@@ -16,5 +16,6 @@ typedef enum VolatileMode {
} VolatileMode;
VolatileMode volatile_mode_from_string(const char *s);
+const char* volatile_mode_to_string(VolatileMode m);
int query_volatile_mode(VolatileMode *ret);