diff options
-rw-r--r-- | src/libsystem/config-parser.c | 28 | ||||
-rw-r--r-- | src/libsystem/config-parser.h | 16 |
2 files changed, 44 insertions, 0 deletions
diff --git a/src/libsystem/config-parser.c b/src/libsystem/config-parser.c index 3319056..e6ade0e 100644 --- a/src/libsystem/config-parser.c +++ b/src/libsystem/config-parser.c @@ -345,3 +345,31 @@ int config_parse_bytes( return 0; } + +int config_parse_percent( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + int ltype, + const char *rvalue, + void *data) { + + size_t *percent = data, p = 0; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + if (!isempty(rvalue)) { + r = parse_percent(rvalue, &p); + if (r < 0) + return r; + } + + *percent = p; + + return 0; +} diff --git a/src/libsystem/config-parser.h b/src/libsystem/config-parser.h index f2e9d3f..1909fe8 100644 --- a/src/libsystem/config-parser.h +++ b/src/libsystem/config-parser.h @@ -171,6 +171,22 @@ int config_parse_string(const char *filename, unsigned line, const char *section */ int config_parse_bytes(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data); +/** + * @brief A common percent(%) type rvalue parser. The right value has + * to be end with '%'. + * + * @param filename a parsing config file name + * @param line a parsing config file line + * @param section a parsing config file section + * @param lvalue a parsing config file left value + * @param ltype a parsing config file left value type. (not used.) + * @param rvalue a parsing config file rvalue + * @param data user data + * + * @return 0 on success, -errno on failure. + */ +int config_parse_percent(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data); + #ifdef __cplusplus } #endif |