diff options
Diffstat (limited to 'libglusterfs/src/common-utils.c')
-rw-r--r-- | libglusterfs/src/common-utils.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 616c7a8ce68..acac5e05281 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -796,6 +796,39 @@ _gf_string2uint (const char *str, unsigned int *n, int base) } static int +_gf_string2double (const char *str, double *n) +{ + double value = 0.0; + char *tail = NULL; + int old_errno = 0; + + if (str == NULL || n == NULL) { + errno = EINVAL; + return -1; + } + + old_errno = errno; + errno = 0; + value = strtod (str, &tail); + + if (errno == ERANGE || errno == EINVAL) { + return -1; + } + + if (errno == 0) { + errno = old_errno; + } + + if (tail[0] != '\0') { + return -1; + } + + *n = value; + + return 0; +} + +static int _gf_string2longlong (const char *str, long long *n, int base) { long long value = 0; @@ -911,6 +944,12 @@ gf_string2uint (const char *str, unsigned int *n) return _gf_string2uint (str, n, 0); } +int +gf_string2double (const char *str, double *n) +{ + return _gf_string2double (str, n); +} + int gf_string2longlong (const char *str, long long *n) { |