X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Ftarget_set.c;h=daeaf8be62f7c2d9779b66f2643dd0e447ac6bd5;hb=979b0fa58b2de639ff79209eff12ec17ff593483;hp=41133e378eb3797e34d68d07c51f5129651317b3;hpb=84dd85dc85cc2325f9c54100ca3fd7d4842db06f;p=collectd.git diff --git a/src/target_set.c b/src/target_set.c index 41133e37..daeaf8be 100644 --- a/src/target_set.c +++ b/src/target_set.c @@ -38,57 +38,25 @@ struct ts_data_s }; 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 */