diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-01-31 20:53:34 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-01-31 20:53:34 +0100 |
commit | 9ba1a1598549148fdc9bd7e1b6b7c3b12b2ea958 (patch) | |
tree | d7bec9e4c925f007991eed86a7f0b96f5afe6225 /src/conf-parser.c | |
parent | be19b7df6ebe9cc521e929c5de2fe74ef84f7f80 (diff) |
load-fragment: properly parse size values denoted in bytes
Diffstat (limited to 'src/conf-parser.c')
-rw-r--r-- | src/conf-parser.c | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/src/conf-parser.c b/src/conf-parser.c index ac8d9f5ac5..c7dd01aa1d 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; } @@ -782,30 +809,3 @@ int config_parse_mode( *m = (mode_t) l; return 0; } - -int config_parse_bytes( - 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; - } - - return 0; -} |