]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/volatile-util.c
volatile-mode: use the usual string table macros for implementing volatile_mode_from_...
[thirdparty/systemd.git] / src / shared / volatile-util.c
index d70d5856d328069ee0f78c82389d2bd5f9df086d..a20f0b43f45bd68dba1b3f5084364205ea96d794 100644 (file)
 #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);