From: Florian Forster Date: Tue, 1 Dec 2009 11:07:07 +0000 (+0100) Subject: src/configfile.[ch]: Add “cf_util_get_boolean”. X-Git-Tag: collectd-4.9.0~36^2~1 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=e1f8ca7870eb6eedb2c8721d96b5cbed4b8cb064;p=collectd.git src/configfile.[ch]: Add “cf_util_get_boolean”. --- diff --git a/src/configfile.c b/src/configfile.c index 1a957f67..592ecbf9 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -943,6 +943,23 @@ int cf_util_get_string (const oconfig_item_t *ci, char **ret_string) /* {{{ */ return (0); } /* }}} int cf_util_get_string */ +int cf_util_get_boolean (const oconfig_item_t *ci, _Bool *ret_bool) /* {{{ */ +{ + if ((ci == NULL) || (ret_bool == NULL)) + return (EINVAL); + + if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) + { + ERROR ("cf_util_get_boolean: The %s option requires " + "exactly one string argument.", ci->key); + return (-1); + } + + *ret_bool = ci->values[0].value.boolean ? true : false; + + return (0); +} /* }}} int cf_util_get_boolean */ + /* Assures that the config option is a string. The string is then converted to * a port number using `service_name_to_port_number' and returned. Returns the * port number in the range [1-65535] or less than zero upon failure. */ diff --git a/src/configfile.h b/src/configfile.h index 74d074ed..a73def21 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -91,6 +91,10 @@ const char *global_option_get (const char *option); * success. */ int cf_util_get_string (const oconfig_item_t *ci, char **ret_string); +/* Assures the config option is a boolean and assignes it to `ret_bool'. + * Otherwise, `ret_bool' is not changed and non-zero is returned. */ +int cf_util_get_boolean (const oconfig_item_t *ci, _Bool *ret_bool); + /* Assures that the config option is a string. The string is then converted to * a port number using `service_name_to_port_number' and returned. Returns the * port number in the range [1-65535] or less than zero upon failure. */