summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 551d51b)
raw | patch | inline | side by side (parent: 551d51b)
author | Florian Forster <octo@collectd.org> | |
Sun, 7 Sep 2014 06:13:19 +0000 (08:13 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 8 Sep 2014 05:13:58 +0000 (07:13 +0200) |
src/target_set.c | patch | blob | history |
diff --git a/src/target_set.c b/src/target_set.c
index 41133e378eb3797e34d68d07c51f5129651317b3..daeaf8be62f7c2d9779b66f2643dd0e447ac6bd5 100644 (file)
--- a/src/target_set.c
+++ b/src/target_set.c
};
typedef struct ts_data_s ts_data_t;
-static char *ts_strdup (const char *orig) /* {{{ */
-{
- size_t sz;
- char *dest;
-
- if (orig == NULL)
- return (NULL);
-
- sz = strlen (orig) + 1;
- dest = (char *) malloc (sz);
- if (dest == NULL)
- return (NULL);
-
- memcpy (dest, orig, sz);
-
- return (dest);
-} /* }}} char *ts_strdup */
-
static int ts_config_add_string (char **dest, /* {{{ */
const oconfig_item_t *ci, int may_be_empty)
{
- char *temp;
-
- if (dest == NULL)
- return (-EINVAL);
+ char *tmp = NULL;
+ int status;
- if ((ci->values_num != 1)
- || (ci->values[0].type != OCONFIG_TYPE_STRING))
- {
- ERROR ("Target `set': The `%s' option requires exactly one string "
- "argument.", ci->key);
- return (-1);
- }
+ status = cf_util_get_string (ci, &tmp);
+ if (status != 0)
+ return (status);
- if ((!may_be_empty) && (ci->values[0].value.string[0] == 0))
+ if (!may_be_empty && (strlen (tmp) == 0))
{
ERROR ("Target `set': The `%s' option does not accept empty strings.",
ci->key);
+ sfree (tmp);
return (-1);
}
- temp = ts_strdup (ci->values[0].value.string);
- if (temp == NULL)
- {
- ERROR ("ts_config_add_string: ts_strdup failed.");
- return (-1);
- }
-
- free (*dest);
- *dest = temp;
-
+ *dest = tmp;
return (0);
} /* }}} int ts_config_add_string */