mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 16:37:19 +09:00
parse-util: add parse_tristate() and use it everywhere
We parse tristates all the time, let's add an explicit parser for them.
This commit is contained in:
committed by
Yu Watanabe
parent
6a4d0efa00
commit
b71a721fbc
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user