From e1f8ca7870eb6eedb2c8721d96b5cbed4b8cb064 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Tue, 1 Dec 2009 12:07:07 +0100 Subject: [PATCH] =?utf8?q?src/configfile.[ch]:=20Add=20=E2=80=9Ccf=5Futil?= =?utf8?q?=5Fget=5Fboolean=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/configfile.c | 17 +++++++++++++++++ src/configfile.h | 4 ++++ 2 files changed, 21 insertions(+) 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. */ -- 2.11.0