diff options
Diffstat (limited to '')
-rw-r--r-- | src/conf.c | 20 | ||||
-rw-r--r-- | src/conf.h | 3 |
2 files changed, 23 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) { diff --git a/src/conf.h b/src/conf.h index f94f6554f..e9c750368 100644 --- a/src/conf.h +++ b/src/conf.h @@ -110,6 +110,9 @@ config_get_string(const char *name, const char *default_value); const char * config_get_path(const char *name); +unsigned +config_get_positive(const char *name, unsigned default_value); + struct block_param * getBlockParam(struct config_param *param, const char *name); |