From b5e0ee918fdff566e45bb255130b9efa6b8fb7b0 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 19 Feb 2009 10:34:28 -0800 Subject: new function gf_string2double for float/double values fixed warning Signed-off-by: Anand V. Avati --- libglusterfs/src/common-utils.c | 39 +++++++++++++++++++++++++++++++++++++++ libglusterfs/src/common-utils.h | 1 + 2 files changed, 40 insertions(+) diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 616c7a8ce..acac5e052 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -795,6 +795,39 @@ _gf_string2uint (const char *str, unsigned int *n, int base) return 0; } +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) { @@ -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) { diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 2016b51eb..6c7390571 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -281,6 +281,7 @@ int gf_string2long (const char *str, long *n); int gf_string2ulong (const char *str, unsigned long *n); int gf_string2int (const char *str, int *n); int gf_string2uint (const char *str, unsigned int *n); +int gf_string2double (const char *str, double *n); int gf_string2longlong (const char *str, long long *n); int gf_string2ulonglong (const char *str, unsigned long long *n); -- cgit