diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-11-01 16:48:42 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-11-01 20:52:16 +0100 |
commit | b71a721fbc5bd4e7d45fd39c0af79e985c9c6b22 (patch) | |
tree | da0712dd9ce4e76457f69525cac84b3f7811fde8 /src/basic/parse-util.c | |
parent | build(deps): bump meson from 1.2.2 to 1.2.3 in /.github/workflows (diff) | |
download | systemd-b71a721fbc5bd4e7d45fd39c0af79e985c9c6b22.tar.xz systemd-b71a721fbc5bd4e7d45fd39c0af79e985c9c6b22.zip |
parse-util: add parse_tristate() and use it everywhere
We parse tristates all the time, let's add an explicit parser for them.
Diffstat (limited to 'src/basic/parse-util.c')
-rw-r--r-- | src/basic/parse-util.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c index d39082ed15..dc868c9b8e 100644 --- a/src/basic/parse-util.c +++ b/src/basic/parse-util.c @@ -44,6 +44,24 @@ int parse_boolean(const char *v) { return -EINVAL; } +int parse_tristate_full(const char *v, const char *third, int *ret) { + int r; + + if (isempty(v) || streq_ptr(v, third)) { /* Empty string is always taken as the third/invalid/auto state */ + if (ret) + *ret = -1; + } else { + r = parse_boolean(v); + if (r < 0) + return r; + + if (ret) + *ret = r; + } + + return 0; +} + int parse_pid(const char *s, pid_t* ret_pid) { unsigned long ul = 0; pid_t pid; |