summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 152724949d..f5adedc531 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -353,6 +353,23 @@ int safe_atolli(const char *s, long long int *ret_lli) {
return 0;
}
+int safe_atod(const char *s, double *ret_d) {
+ char *x = NULL;
+ double d;
+
+ assert(s);
+ assert(ret_d);
+
+ errno = 0;
+ d = strtod(s, &x);
+
+ if (!x || x == s || *x || errno)
+ return errno ? -errno : -EINVAL;
+
+ *ret_d = (double) d;
+ return 0;
+}
+
/* Split a string into words. */
char *split(const char *c, size_t *l, const char *separator, char **state) {
char *current;