parse-util: allow parse_boolean() to take a NULL argument

It's pretty useful to allow parse_boolean() to take a NULL argument and
return an error in that case, rather than abort. i.e. making this a
runtime rather than programming error allows us to shorten code
elsewhere.
This commit is contained in:
Lennart Poettering 2018-11-06 12:06:45 +01:00
parent 2987225ce6
commit b06f0cc625
1 changed files with 2 additions and 1 deletions

View File

@ -20,7 +20,8 @@
#include "string-util.h"
int parse_boolean(const char *v) {
assert(v);
if (!v)
return -EINVAL;
if (streq(v, "1") || strcaseeq(v, "yes") || strcaseeq(v, "y") || strcaseeq(v, "true") || strcaseeq(v, "t") || strcaseeq(v, "on"))
return 1;