diff options
author | Max Kellermann <max@duempel.org> | 2009-01-21 08:46:59 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-21 08:46:59 +0100 |
commit | f11eb14c8a7d0134ff5399e1c38777ad7938459a (patch) | |
tree | 86e0f1ceda0b378f4b7894fca958eb278b8256d3 /src/conf.c | |
parent | 17222e95615eab116893d29a7fc78ea63b18f968 (diff) | |
download | mpd-f11eb14c8a7d0134ff5399e1c38777ad7938459a.tar.gz mpd-f11eb14c8a7d0134ff5399e1c38777ad7938459a.tar.xz mpd-f11eb14c8a7d0134ff5399e1c38777ad7938459a.zip |
conf: added config_get_positive()
This convenience function parses a configuration value into a positive
integer. It aborts if parsing fails.
Diffstat (limited to 'src/conf.c')
-rw-r--r-- | src/conf.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/conf.c b/src/conf.c index e017f1209..74e1f5337 100644 --- a/src/conf.c +++ b/src/conf.c @@ -407,6 +407,26 @@ config_get_path(const char *name) return param->value = path; } +unsigned +config_get_positive(const char *name, unsigned default_value) +{ + struct config_param *param = config_get_param(name); + long value; + char *endptr; + + if (param == NULL) + return default_value; + + value = strtol(param->value, &endptr, 0); + if (*endptr != 0) + g_error("Not a valid number in line %i", param->line); + + if (value <= 0) + g_error("Not a positive number in line %i", param->line); + + return (unsigned)value; +} + struct block_param * getBlockParam(struct config_param * param, const char *name) { |