summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3281172)
raw | patch | inline | side by side (parent: 3281172)
author | Florian Forster <octo@collectd.org> | |
Wed, 10 Sep 2014 14:15:40 +0000 (16:15 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Wed, 10 Sep 2014 14:57:03 +0000 (16:57 +0200) |
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history |
diff --git a/src/common.c b/src/common.c
index 8691d3eb2c67516ba7e89a701a83b0749565998a..5386739fbc372e96638ac55c79a91e8ca3af3ca9 100644 (file)
--- a/src/common.c
+++ b/src/common.c
return (0);
} /* }}} int strtoderive */
+int strtogauge (const char *string, gauge_t *ret_value) /* {{{ */
+{
+ gauge_t tmp;
+ char *endptr = NULL;
+
+ if ((string == NULL) || (ret_value == NULL))
+ return (EINVAL);
+
+ errno = 0;
+ endptr = NULL;
+ tmp = (gauge_t) strtod (string, &endptr);
+ if (errno != 0)
+ return (errno);
+ else if ((endptr == NULL) || (*endptr != 0))
+ return (EINVAL);
+
+ *ret_value = tmp;
+ return (0);
+} /* }}} int strtogauge */
+
int strarray_add (char ***ret_array, size_t *ret_array_len, char const *str) /* {{{ */
{
char **array;
diff --git a/src/common.h b/src/common.h
index b2e4c6766ad20b4552f6f64fd49b483fe4aaf7a3..434ed019bc2d1a2359db6bbcf8d982fba98e091c 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);
+/** Parse a string to a gauge_t value. Returns zero on success or non-zero on
+ * failure. If failure is returned, ret_value is not touched. */
+int strtogauge (const char *string, gauge_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);