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.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user