X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fconf-parser.c;h=c7dd01aa1d5347c3e0355cc1c8548e5ae94208cd;hb=bacbccb78cec45c4759ef4291375605284248eb0;hp=a71dcd0d8fb8c87460ea24f81b244334ce740519;hpb=8ea913b2eaadbd92e069ea6b71cc5f5df409decf;p=elogind.git diff --git a/src/conf-parser.c b/src/conf-parser.c index a71dcd0d8..c7dd01aa1 100644 --- a/src/conf-parser.c +++ b/src/conf-parser.c @@ -454,7 +454,7 @@ int config_parse_unsigned( return 0; } -int config_parse_size( +int config_parse_bytes_size( const char *filename, unsigned line, const char *section, @@ -465,20 +465,47 @@ int config_parse_size( void *userdata) { size_t *sz = data; - unsigned u; - int r; + off_t o; assert(filename); assert(lvalue); assert(rvalue); assert(data); - if ((r = safe_atou(rvalue, &u)) < 0) { - log_error("[%s:%u] Failed to parse numeric value, ignoring: %s", filename, line, rvalue); + if (parse_bytes(rvalue, &o) < 0 || (off_t) (size_t) o != o) { + log_error("[%s:%u] Failed to parse byte value, ignoring: %s", filename, line, rvalue); + return 0; + } + + *sz = (size_t) o; + return 0; +} + + +int config_parse_bytes_off( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + off_t *bytes = data; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + assert_cc(sizeof(off_t) == sizeof(uint64_t)); + + if (parse_bytes(rvalue, bytes) < 0) { + log_error("[%s:%u] Failed to parse bytes value, ignoring: %s", filename, line, rvalue); return 0; } - *sz = (size_t) u; return 0; } @@ -509,6 +536,36 @@ int config_parse_bool( return 0; } +int config_parse_tristate( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + int k; + int *b = data; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + /* Tristates are like booleans, but can also take the 'default' value, i.e. "-1" */ + + k = parse_boolean(rvalue); + if (k < 0) { + log_error("[%s:%u] Failed to parse boolean value, ignoring: %s", filename, line, rvalue); + return 0; + } + + *b = !!k; + return 0; +} + int config_parse_string( const char *filename, unsigned line,