summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 525de68)
raw | patch | inline | side by side (parent: 525de68)
author | Florian Forster <octo@noris.net> | |
Wed, 10 Mar 2010 16:20:29 +0000 (17:20 +0100) | ||
committer | Florian Forster <octo@noris.net> | |
Wed, 10 Mar 2010 16:20:29 +0000 (17:20 +0100) |
A function to parse a config node into a char buffer of limited size.
src/configfile.c | patch | blob | history | |
src/configfile.h | patch | blob | history |
diff --git a/src/configfile.c b/src/configfile.c
index b2997d647233b3a1bf3c63994ffe7e89865e40e6..1bd02a82d945b418ee32e3c08fd58b29f5857717 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
return (0);
} /* }}} int cf_util_get_string */
+/* Assures the config option is a string and copies it to the provided buffer.
+ * Assures null-termination. */
+int cf_util_get_string_buffer (const oconfig_item_t *ci, char *buffer, /* {{{ */
+ size_t buffer_size)
+{
+ if ((ci == NULL) || (buffer == NULL) || (buffer_size < 1))
+ return (EINVAL);
+
+ if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+ {
+ ERROR ("cf_util_get_string_buffer: The %s option requires "
+ "exactly one string argument.", ci->key);
+ return (-1);
+ }
+
+ strncpy (buffer, ci->values[0].value.string, buffer_size);
+ buffer[buffer_size - 1] = 0;
+
+ return (0);
+} /* }}} int cf_util_get_string_buffer */
+
int cf_util_get_boolean (const oconfig_item_t *ci, _Bool *ret_bool) /* {{{ */
{
if ((ci == NULL) || (ret_bool == NULL))
diff --git a/src/configfile.h b/src/configfile.h
index a73def21760f8efbf0a642002c7f8ee5a45aec1d..c1c5e2933ec00b04d8ca744618aa7aa351be2281 100644 (file)
--- a/src/configfile.h
+++ b/src/configfile.h
* success. */
int cf_util_get_string (const oconfig_item_t *ci, char **ret_string);
+/* Assures the config option is a string and copies it to the provided buffer.
+ * Assures null-termination. */
+int cf_util_get_string_buffer (const oconfig_item_t *ci, char *buffer,
+ size_t buffer_size);
+
/* 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);