summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5528a3d)
raw | patch | inline | side by side (parent: 5528a3d)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 24 Sep 2009 15:32:29 +0000 (17:32 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 24 Sep 2009 15:32:29 +0000 (17:32 +0200) |
src/configfile.c | patch | blob | history | |
src/configfile.h | patch | blob | history |
diff --git a/src/configfile.c b/src/configfile.c
index d401a2e1e0e2998a1a965fa9b31acb2532106682..df04289446ccfba23d598d14e80c29ce5a5fa882 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
return (0);
} /* int cf_read */
+
+/* Assures the config option is a string, duplicates it and returns the copy in
+ * "ret_string". If necessary "*ret_string" is freed first. Returns zero upon
+ * success. */
+int cf_util_get_string (const oconfig_item_t *ci, char **ret_string) /* {{{ */
+{
+ char *string;
+
+ if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+ {
+ ERROR ("cf_util_get_string: The %s plugin requires "
+ "exactly one string argument.", ci->key);
+ return (-1);
+ }
+
+ string = strdup (ci->values[0].value.string);
+ if (string == NULL)
+ return (-1);
+
+ if (*ret_string != NULL)
+ sfree (*ret_string);
+ *ret_string = string;
+
+ return (0);
+} /* }}} int cf_util_get_string */
diff --git a/src/configfile.h b/src/configfile.h
index 3952c180d9949f08bc42a94899d23a9c19a5db70..aca58770efbdc9dbd530d06b399fd2d6510158f2 100644 (file)
--- a/src/configfile.h
+++ b/src/configfile.h
int global_option_set (const char *option, const char *value);
const char *global_option_get (const char *option);
+/* Assures the config option is a string, duplicates it and returns the copy in
+ * "ret_string". If necessary "*ret_string" is freed first. Returns zero upon
+ * success. */
+int cf_util_get_string (const oconfig_item_t *ci, char **ret_string);
+
#endif /* defined(CONFIGFILE_H) */