summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8da1109)
raw | patch | inline | side by side (parent: 8da1109)
author | Florian Forster <octo@collectd.org> | |
Fri, 11 Jan 2013 13:56:35 +0000 (14:56 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 11 Jan 2013 13:56:35 +0000 (14:56 +0100) |
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history |
diff --git a/src/common.c b/src/common.c
index b679bf70f4ccff6a385c47b5fb4f47ccbd26a8b1..82a4f017dc9c04a734e47160c10f84b632670b30 100644 (file)
--- a/src/common.c
+++ b/src/common.c
*ret_value = tmp;
return (0);
} /* }}} int strtoderive */
+
+int strarray_add (char ***ret_array, size_t *ret_array_len, char const *str) /* {{{ */
+{
+ char **array;
+ size_t array_len = *ret_array_len;
+
+ if (str == NULL)
+ return (EINVAL);
+
+ array = realloc (*ret_array,
+ (array_len + 1) * sizeof (*array));
+ if (array == NULL)
+ return (ENOMEM);
+ *ret_array = array;
+
+ array[array_len] = strdup (str);
+ if (array[array_len] == NULL)
+ return (ENOMEM);
+
+ array_len++;
+ *ret_array_len = array_len;
+ return (0);
+} /* }}} int strarray_add */
+
+void strarray_free (char **array, size_t array_len) /* {{{ */
+{
+ size_t i;
+
+ for (i = 0; i < array_len; i++)
+ sfree (array[i]);
+ sfree (array);
+} /* }}} void strarray_free */
diff --git a/src/common.h b/src/common.h
index 8a7d986534919efa65e449c17313882f363cce93..2c74436318fecee1f9189bbfb6e658e28531d3f1 100644 (file)
--- a/src/common.h
+++ b/src/common.h
* failure. If failure is returned, ret_value is not touched. */
int strtoderive (const char *string, derive_t *ret_value);
+int strarray_add (char ***ret_array, size_t *ret_array_len, char const *str);
+void strarray_free (char **array, size_t array_len);
+
#endif /* COMMON_H */