]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Removed setlocale calls, used rrd_strtod & rrd_snprintf
authorUpasana <me@upasana.me>
Sun, 29 Jun 2014 11:59:48 +0000 (17:29 +0530)
committerUpasana <me@upasana.me>
Tue, 1 Jul 2014 19:36:08 +0000 (01:06 +0530)
12 files changed:
src/Makefile.am
src/rrd_client.c
src/rrd_create.c
src/rrd_daemon.c
src/rrd_fetch_libdbi.c
src/rrd_graph.c
src/rrd_graph_helper.c
src/rrd_restore.c
src/rrd_rpncalc.c
src/rrd_tune.c
src/rrd_update.c
src/rrd_xport.c

index 2566aba277696f85b1d2ca411b3acc395f9e742f..108787b1deb5ca230139e30f7a7d0b24abb5d235 100644 (file)
@@ -18,6 +18,7 @@ AM_CFLAGS = @CFLAGS@ -I$(top_srcdir)
 
 UPD_C_FILES =          \
        mutex.c         \
+        rrd_strtod.c    \
        rrd_create.c    \
        hash_32.c       \
        rrd_parsetime.c \
@@ -62,6 +63,7 @@ noinst_HEADERS = \
        unused.h \
         gettext.h \
        mutex.h \
+        rrd_strtod.h \
        rrd_snprintf.h \
        rrd_getopt.h rrd_parsetime.h \
        rrd_config_bottom.h rrd_i18n.h \
@@ -125,7 +127,7 @@ rrdtool_LDADD       = librrd.la
 rrdcached_SOURCES = rrd_daemon.c
 rrdcached_DEPENDENCIES = librrd_th.la
 rrdcached_CPPFLAGS = -DVERSION='"$(VERSION)"' -DLOCALSTATEDIR='"$(localstatedir)"'
-rrdcached_LDADD = librrd_th.la $(ALL_LIBS)
+rrdcached_LDADD = rrd_strtod.o librrd_th.la $(ALL_LIBS)
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = librrd.pc
index 6c7b46ceafb5a1be19307016afad9c7754d5b3c7..5e744c6b1dd95d91c7081ebc20178a300eb5fb23 100644 (file)
@@ -35,6 +35,7 @@
 #include <locale.h>
 #endif
 
+#include "rrd_strtod.h"
 #include "rrd.h"
 #include "rrd_tool.h"
 #include "rrd_client.h"
@@ -240,7 +241,6 @@ static int parse_value_array_header (char *line, /* {{{ */
   char *str_key;
   char **str_array;
   char *endptr;
-  char *old_locale;
   int status;
   size_t i;
 
@@ -266,21 +266,17 @@ static int parse_value_array_header (char *line, /* {{{ */
   /* Enforce the "C" locale so that parsing of the response is not dependent on
    * the locale. For example, when using a German locale the strtod() function
    * will expect a comma as the decimal separator, i.e. "42,77". */
-  old_locale = setlocale (LC_NUMERIC, "C");
-
   for (i = 0; i < array_len; i++)
   {
     endptr = NULL;
-    array[i] = (rrd_value_t) strtod (str_array[i], &endptr);
+    array[i] = (rrd_value_t) rrd_strtod (str_array[i], &endptr);
     if ((endptr == str_array[i]) || (errno != 0))
     {
-      (void) setlocale (LC_NUMERIC, old_locale);
       free(str_array);
       return (-1);
     }
   }
 
-  (void) setlocale (LC_NUMERIC, old_locale);
   free(str_array);
   return (0);
 } /* }}} int parse_value_array_header */
@@ -1590,7 +1586,7 @@ int rrdc_stats_get (rrdc_stats_t **ret_stats) /* {{{ */
         || (strcmp ("TreeNodesNumber", key) == 0))
     {
       s->type = RRDC_STATS_TYPE_GAUGE;
-      s->value.gauge = strtod (value, &endptr);
+      s->value.gauge = rrd_strtod (value, &endptr);
     }
     else if ((strcmp ("DataSetsWritten", key) == 0)
         || (strcmp ("FlushesReceived", key) == 0)
index 18781fae47aa8cd768199f233601bcff053619ca..39bdb19e9bd9c556091ebb52492a4f4affdd6bd0 100644 (file)
@@ -9,6 +9,7 @@
 #include <locale.h>
 #include <math.h>
 
+#include "rrd_strtod.h"
 #include "rrd_tool.h"
 #include "rrd_rpncalc.h"
 #include "rrd_hw.h"
@@ -629,7 +630,6 @@ void parseGENERIC_DS(
     ds_def_t *ds_def)
 {
     char      minstr[DS_NAM_SIZE], maxstr[DS_NAM_SIZE];
-    char     *old_locale;
     const char *parsetime_error = NULL;
 
     /*
@@ -639,7 +639,6 @@ void parseGENERIC_DS(
        &(rrd -> ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt),
        minstr,maxstr);
      */
-    old_locale = setlocale(LC_NUMERIC, "C");
     do {
         char      numbuf[32];
         size_t    heartbeat_len;
@@ -667,12 +666,12 @@ void parseGENERIC_DS(
             if (minstr[0] == 'U' && minstr[1] == 0)
                 ds_def->par[DS_min_val].u_val = DNAN;
             else
-                ds_def->par[DS_min_val].u_val = atof(minstr);
+                ds_def->par[DS_min_val].u_val = rrd_strtod(minstr, 0);
 
             if (maxstr[0] == 'U' && maxstr[1] == 0)
                 ds_def->par[DS_max_val].u_val = DNAN;
             else
-                ds_def->par[DS_max_val].u_val = atof(maxstr);
+                ds_def->par[DS_max_val].u_val = rrd_strtod(maxstr, 0);
 
             if (!isnan(ds_def->par[DS_min_val].u_val) &&
                 !isnan(ds_def->par[DS_max_val].u_val) &&
@@ -687,7 +686,6 @@ void parseGENERIC_DS(
     } while (0);
     if (parsetime_error)
         rrd_set_error("failed to parse data source %s: %s", def, parsetime_error);
-    setlocale(LC_NUMERIC, old_locale);
 }
 
 /* Create the CF_DEVPREDICT, CF_DEVSEASONAL, CF_SEASONAL, and CF_FAILURES RRAs
index beaf30e8a1de685b8b1b92dfc38216df3fef4725..b949d900549febabfb0b779ce8b5d6c75bd53479 100644 (file)
 #include <tcpd.h>
 #endif /* HAVE_LIBWRAP */
 
+#include "rrd_strtod.h"
 #include <glib.h>
 /* }}} */
 
@@ -1511,7 +1512,7 @@ static int handle_request_update (HANDLER_PROTO) /* {{{ */
 
     /* make sure update time is always moving forward. We use double here since
        update does support subsecond precision for timestamps ... */
-    stamp = strtod(value, &eostamp);
+    stamp = rrd_strtod(value, &eostamp);
     if (eostamp == value || eostamp == NULL || *eostamp != ':')
     {
       pthread_mutex_unlock(&cache_lock);
index d564bf3ae693eed87b5f5f9eac7791edeb344164..d90a3032d456f5e1dd528021628790d90ecfcd2d 100644 (file)
@@ -1,5 +1,6 @@
 #include "rrd_tool.h"
 #include "unused.h"
+#include "rrd_strtod.h"
 #include <dbi/dbi.h>
 #include <time.h>
 
@@ -100,7 +101,7 @@ static double rrd_fetch_dbi_double(dbi_result *result,int idx) {
   switch (type) {
     case DBI_TYPE_STRING:
       ptmp=(char*)dbi_result_get_string_idx(result,idx);
-      value=strtod(ptmp,NULL);
+      value=rrd_strtod(ptmp,NULL);
       break;
     case DBI_TYPE_INTEGER:
       if        (attr & DBI_INTEGER_SIZE1) { value=dbi_result_get_char_idx(result,idx);
@@ -130,7 +131,7 @@ static double rrd_fetch_dbi_double(dbi_result *result,int idx) {
        }
       }
       /* convert to number */
-      value=strtod(ptmp,NULL);
+      value=rrd_strtod(ptmp,NULL);
       /* free pointer */
       free(ptmp);
       break;
index c7a655def1c7dff42266c435699e26c145bbf935..5c322d6b96f752d427f2f7b6c646d160679925ac 100644 (file)
@@ -11,6 +11,8 @@
 #include "strftime.h"
 #endif
 
+#include "rrd_strtod.h"
+
 #include "rrd_tool.h"
 #include "unused.h"
 
@@ -4182,20 +4184,16 @@ rrd_info_t *rrd_graph_v(
 {
     image_desc_t im;
     rrd_info_t *grinfo;
-    char *old_locale;
     rrd_graph_init(&im);
     /* a dummy surface so that we can measure text sizes for placements */
-    old_locale = setlocale(LC_NUMERIC, "C");
     rrd_graph_options(argc, argv, &im);
     if (rrd_test_error()) {
-        setlocale(LC_NUMERIC, old_locale); /* reenable locale */
         rrd_info_free(im.grinfo);
         im_free(&im);
         return NULL;
     }
 
     if (optind >= argc) {
-        setlocale(LC_NUMERIC, old_locale); /* reenable locale */
         rrd_info_free(im.grinfo);
         im_free(&im);
         rrd_set_error("missing filename");
@@ -4203,7 +4201,6 @@ rrd_info_t *rrd_graph_v(
     }
 
     if (strlen(argv[optind]) >= MAXPATH) {
-        setlocale(LC_NUMERIC, old_locale); /* reenable locale */
         rrd_set_error("filename (including path) too long");
         rrd_info_free(im.grinfo);
         im_free(&im);
@@ -4218,7 +4215,6 @@ rrd_info_t *rrd_graph_v(
     }
 
     rrd_graph_script(argc, argv, &im, 1);
-    setlocale(LC_NUMERIC, old_locale); /* reenable locale for rendering the graph */
 
     if (rrd_test_error()) {
         rrd_info_free(im.grinfo);
@@ -4424,6 +4420,7 @@ void rrd_graph_options(
     int       stroff;
     char     *parsetime_error = NULL;
     char      scan_gtm[12], scan_mtm[12], scan_ltm[12], col_nam[12];
+    char      double_str[20], double_str2[20];
     time_t    start_tmp = 0, end_tmp = 0;
     long      long_tmp;
     rrd_time_value_t start_tv, end_tv;
@@ -4586,7 +4583,7 @@ void rrd_graph_options(
             im->forceleftspace = 1;
             break;
         case 'T':
-            im->tabwidth = atof(optarg);
+            im->tabwidth = rrd_strtod(optarg, 0);
             break;
         case 'S':
             im->step = atoi(optarg);
@@ -4650,12 +4647,12 @@ void rrd_graph_options(
             }
             break;
         case 'y':
-
             if (strcmp(optarg, "none") == 0) {
                 im->draw_y_grid = 0;
                 break;
             };
-            if (sscanf(optarg, "%lf:%d", &im->ygridstep, &im->ylabfact) == 2) {
+            if (sscanf(optarg, "%[-0-9.e+]:%d", double_str , &im->ylabfact) == 2) {
+                im->ygridstep = rrd_strtod( double_str, 0 );
                 if (im->ygridstep <= 0) {
                     rrd_set_error("grid step must be > 0");
                     return;
@@ -4673,9 +4670,11 @@ void rrd_graph_options(
             break;
         case 1008: /* grid-dash */
             if(sscanf(optarg,
-                      "%lf:%lf",
-                      &im->grid_dash_on,
-                      &im->grid_dash_off) != 2) {
+                      "%[-0-9.e+]:%[-0-9.e+]",
+                      double_str,
+                      double_str2 ) != 2) {
+                im->grid_dash_on = rrd_strtod( double_str, 0 );
+                im->grid_dash_off = rrd_strtod( double_str2, 0 );
                 rrd_set_error("expected grid-dash format float:float");
                 return;
             }
@@ -4688,11 +4687,12 @@ void rrd_graph_options(
             week_fmt[(sizeof week_fmt)-1]='\0';
             break;
         case 1002: /* right y axis */
-
             if(sscanf(optarg,
-                      "%lf:%lf",
-                      &im->second_axis_scale,
-                      &im->second_axis_shift) == 2) {
+                      "%[-0-9.e+]:%[-0-9.e+]",
+                      double_str,
+                      double_str2 ) == 2) {
+                im->second_axis_scale = rrd_strtod( double_str, 0 );
+                im->second_axis_shift = rrd_strtod( double_str2, 0 );
                 if(im->second_axis_scale==0){
                     rrd_set_error("the second_axis_scale  must not be 0");
                     return;
@@ -4739,10 +4739,10 @@ void rrd_graph_options(
                        }
             break;
         case 'u':
-            im->maxval = atof(optarg);
+            im->maxval = rrd_strtod(optarg, 0);
             break;
         case 'l':
-            im->minval = atof(optarg);
+            im->minval = rrd_strtod(optarg, 0);
             break;
         case 'b':
             im->base = atol(optarg);
@@ -4854,7 +4854,8 @@ void rrd_graph_options(
             double    size = 1;
             int       end;
 
-            if (sscanf(optarg, "%10[A-Z]:%lf%n", prop, &size, &end) >= 2) {
+            if (sscanf(optarg, "%10[A-Z]:%[-0-9.e+]%n", prop, double_str, &end) >= 2) {
+                size = rrd_strtod( double_str, 0 );
                 int       sindex, propidx;
 
                 if ((sindex = text_prop_conv(prop)) != -1) {
@@ -4889,7 +4890,7 @@ void rrd_graph_options(
             break;
         }
         case 'm':
-            im->zoom = atof(optarg);
+            im->zoom = rrd_strtod(optarg, 0);
             if (im->zoom <= 0.0) {
                 rrd_set_error("zoom factor must be > 0");
                 return;
@@ -5156,11 +5157,12 @@ int vdef_parse(
      * so the parsing is rather simple.  Change if needed.
      */
     double    param;
-    char      func[30];
+    char      func[30], double_str[12];
     int       n;
 
     n = 0;
-    sscanf(str, "%le,%29[A-Z]%n", &param, func, &n);
+    sscanf(str, "%[-0-9.e+],%29[A-Z]%n", double_str, func, &n);
+    param = rrd_strtod( double_str, 0 );
     if (n == (int) strlen(str)) {   /* matched */
         ;
     } else {
index d45eadd081ab2332d1851e00ac297f66ed510fe7..19ec8c4a7dbccecc6d9122b15bc8bb226991ed85 100644 (file)
@@ -12,6 +12,7 @@
 #endif
 
 #include "rrd_graph.h"
+#include "rrd_strtod.h"
 
 #define dprintf(...) if (gdp->debug&1) fprintf(stderr,__VA_ARGS__);
 #define dprintfparsed(...) if (gdp->debug&2) fprintf(stderr,__VA_ARGS__);
@@ -140,19 +141,15 @@ int getLong(const char* v,long *val,char**extra,int base) {
 int getDouble(const char* v, double *val,char**extra) {
   /* try to execute the parser */
   /* NOTE that this may be a bit different from the original parser */
-  char *old_locale;
   *extra=NULL;
-  old_locale = setlocale(LC_NUMERIC, "C");
   errno = 0;
-  *val = strtod(v,extra);
+  *val = rrd_strtod(v,extra);
   if (errno > 0) {
       rrd_set_error("converting '%s' to float: %s", v, rrd_strerror(errno));
-      setlocale(LC_NUMERIC, old_locale);
       return -1;
   };
-  setlocale(LC_NUMERIC, old_locale);
 
-  *val=strtod(v,extra);
+  *val=rrd_strtod(v,extra);
   /* and error handling */
   if (extra==NULL) {
     return 0;
index b7f1d04fbb59a01c63a64fcb0e58836148b1181a..6a509b97191d8dc99f7b9b7b4e717565b80dab9e 100644 (file)
@@ -13,6 +13,7 @@
 #include "rrd_rpncalc.h"
 #include "rrd_restore.h"
 #include "unused.h"
+#include "rrd_strtod.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -329,7 +330,7 @@ static int get_xml_double(
             return 0;            
         }        
         errno = 0;
-        temp = strtod((char *)text,NULL);
+        temp = rrd_strtod((char *)text,NULL);
         if (errno>0){
             rrd_set_error("ling %d: get_xml_double from '%s' %s",
                           xmlTextReaderGetParserLineNumber(reader),
@@ -1347,7 +1348,6 @@ int rrd_restore(
     char **argv)
 {
     rrd_t    *rrd;
-    char     *old_locale;
     /* init rrd clean */
     optind = 0;
     opterr = 0;         /* initialize getopt */
@@ -1389,12 +1389,8 @@ int rrd_restore(
         return (-1);
     }
 
-    old_locale = setlocale(LC_NUMERIC, "C");
-
     rrd = parse_file(argv[optind]);
 
-    setlocale(LC_NUMERIC, old_locale);
-
     if (rrd == NULL)
         return (-1);
     
index 1796e47bb89ec1721799408db3d80c3c5f7e09f4..f0c00cba88738be66cd148e97e3946594b4273e1 100644 (file)
@@ -8,6 +8,7 @@
 #include <locale.h>
 #include <stdlib.h>
 
+#include "rrd_strtod.h"
 #include "rrd_tool.h"
 #include "rrd_rpncalc.h"
 // #include "rrd_graph.h"
@@ -304,9 +305,7 @@ rpnp_t   *rpn_parse(
     long      steps = -1;
     rpnp_t   *rpnp;
     char      vname[MAX_VNAME_LEN + 10];
-    char     *old_locale;
-
-    old_locale = setlocale(LC_NUMERIC, "C");
+    char      double_str[20];
 
     rpnp = NULL;
     expr = (char *) expr_const;
@@ -314,12 +313,12 @@ rpnp_t   *rpn_parse(
     while (*expr) {
         if ((rpnp = (rpnp_t *) rrd_realloc(rpnp, (++steps + 2) *
                                            sizeof(rpnp_t))) == NULL) {
-            setlocale(LC_NUMERIC, old_locale);
             return NULL;
         }
 
-        else if ((sscanf(expr, "%lf%n", &rpnp[steps].val, &pos) == 1)
+        else if ((sscanf(expr, "%[-0-9.e+]%n", double_str, &pos) == 1)
                  && (expr[pos] == ',')) {
+            rpnp[steps].val = rrd_strtod( double_str, 0 );
             rpnp[steps].op = OP_NUMBER;
             expr += pos;
         }
@@ -409,7 +408,6 @@ rpnp_t   *rpn_parse(
 
         else {
             rrd_set_error("don't undestand '%s'",expr);
-            setlocale(LC_NUMERIC, old_locale);
             free(rpnp);
             return NULL;
         }
@@ -422,13 +420,11 @@ rpnp_t   *rpn_parse(
         if (*expr == ',')
             expr++;
         else {
-            setlocale(LC_NUMERIC, old_locale);
             free(rpnp);
             return NULL;
         }
     }
     rpnp[steps + 1].op = OP_END;
-    setlocale(LC_NUMERIC, old_locale);
     return rpnp;
 }
 
index d7abe34d48b8d8782f6c4c60110099bc213e7acb..41ed3b0f587cd1f1358cc0418ddbe546061413e4 100644 (file)
@@ -42,6 +42,7 @@
 #include <stdlib.h>
 #include <locale.h>
 
+#include "rrd_strtod.h"
 #include "rrd_tool.h"
 #include "rrd_rpncalc.h"
 #include "rrd_hw.h"
@@ -79,13 +80,14 @@ int rrd_tune(
     char      ds_nam[DS_NAM_SIZE];
     char      ds_new[DS_NAM_SIZE];
     long      heartbeat;
-    double    min;
-    double    max;
+    double    min = 0;
+    double    max = 0;
     char      dst[DST_SIZE];
     int       rc = -1;
     int       opt_newstep = -1;
     rrd_file_t *rrd_file = NULL;
     char      *opt_daemon = NULL;
+    char      double_str[ 12 ];
     struct option long_options[] = {
         {"heartbeat", required_argument, 0, 'h'},
         {"minimum", required_argument, 0, 'i'},
@@ -110,7 +112,6 @@ int rrd_tune(
         {"daemon", required_argument, 0, 'D'},
         {0, 0, 0, 0}
     };
-    char     *old_locale = setlocale(LC_NUMERIC, "C");
 
     optind = 0;
     opterr = 0;         /* initialize getopt */
@@ -206,10 +207,11 @@ int rrd_tune(
 
         case 'i':
             if ((matches =
-                 sscanf(optarg, DS_NAM_FMT ":%lf", ds_nam, &min)) < 1) {
+                 sscanf(optarg, DS_NAM_FMT ":%[-0-9.e+]", ds_nam, double_str)) < 1) {
                 rrd_set_error("invalid arguments for minimum ds value");
                goto done;
             }
+            min = rrd_strtod( double_str, 0 );
             if ((ds = ds_match(&rrd, ds_nam)) == -1) {
                goto done;
             }
@@ -221,10 +223,11 @@ int rrd_tune(
 
         case 'a':
             if ((matches =
-                 sscanf(optarg, DS_NAM_FMT ":%lf", ds_nam, &max)) < 1) {
+                 sscanf(optarg, DS_NAM_FMT ":%[-0-9.e+]", ds_nam, double_str)) < 1) {
                 rrd_set_error("invalid arguments for maximum ds value");
                goto done;
             }
+            max = rrd_strtod( double_str, 0 );
             if ((ds = ds_match(&rrd, ds_nam)) == -1) {
                goto done;
             }
@@ -399,9 +402,6 @@ int rrd_tune(
     
     rc = 0;
 done:
-    if (old_locale) {
-       setlocale(LC_NUMERIC, old_locale);
-    }
     if (rrd_file) {
        rrd_close(rrd_file);
     }
@@ -420,7 +420,7 @@ int set_hwarg(
     signed short rra_idx = -1;
 
     /* read the value */
-    param = atof(arg);
+    param = rrd_strtod(arg, 0);
     if (param <= 0.0 || param >= 1.0) {
         rrd_set_error("Holt-Winters parameter must be between 0 and 1");
         return -1;
@@ -453,7 +453,7 @@ int set_hwsmootharg(
     signed short rra_idx = -1;
 
     /* read the value */
-    param = atof(arg);
+    param = rrd_strtod(arg, 0);
     /* in order to avoid smoothing of SEASONAL or DEVSEASONAL, we need to 
      * the 0.0 value*/
     if (param < 0.0 || param > 1.0) {
@@ -486,7 +486,7 @@ int set_deltaarg(
     unsigned long i;
     signed short rra_idx = -1;
 
-    param = atof(arg);
+    param = rrd_strtod(arg, 0);
     if (param < 0.1) {
         rrd_set_error("Parameter specified is too small");
         return -1;
index a26005e0e258d2eb17f615c20d928536b08816d0..03fae8fdd487aad9b1c8889d449f0631996da8b1 100644 (file)
@@ -28,6 +28,8 @@
 #include "rrd_update.h"
 #include <glib.h>
 
+#include "rrd_strtod.h"
+
 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
 
 /*
@@ -1292,7 +1294,6 @@ static int get_time_from_reading(
 {
     double    tmp;
     char     *parsetime_error = NULL;
-    char     *old_locale;
     rrd_time_value_t ds_tv;
     struct timeval tmp_time;    /* used for time conversion */
 
@@ -1316,15 +1317,13 @@ static int get_time_from_reading(
         *current_time = tmp_time.tv_sec;
         *current_time_usec = tmp_time.tv_usec;
     } else {
-       old_locale = setlocale(LC_NUMERIC, "C");
         errno = 0;
-        tmp = strtod(updvals[0], 0);
+        tmp = rrd_strtod(updvals[0], 0);
         if (errno > 0) {
             rrd_set_error("converting '%s' to float: %s",
                 updvals[0], rrd_strerror(errno));
             return -1;
         };
-        setlocale(LC_NUMERIC, old_locale);
         if (tmp < 0.0){
             gettimeofday(&tmp_time, 0);
             tmp = (double)tmp_time.tv_sec + (double)tmp_time.tv_usec * 1e-6f + tmp;
@@ -1364,7 +1363,6 @@ static int update_pdp_prep(
     int       ii;
     char     *endptr;   /* used in the conversion */
     double    rate;
-    char     *old_locale;
     enum dst_en dst_idx;
 
     for (ds_idx = 0; ds_idx < rrd->stat_head->ds_cnt; ds_idx++) {
@@ -1428,15 +1426,13 @@ static int update_pdp_prep(
                 }
                 break;
             case DST_ABSOLUTE:
-               old_locale = setlocale(LC_NUMERIC, "C");
                 errno = 0;
-                pdp_new[ds_idx] = strtod(updvals[ds_idx + 1], &endptr);
+                pdp_new[ds_idx] = rrd_strtod(updvals[ds_idx + 1], &endptr);
                 if (errno > 0) {
                     rrd_set_error("converting '%s' to float: %s",
                                   updvals[ds_idx + 1], rrd_strerror(errno));
                     return -1;
                 };
-                setlocale(LC_NUMERIC, old_locale);
                 if (endptr[0] != '\0') {
                     rrd_set_error
                         ("conversion of '%s' to float not complete: tail '%s'",
@@ -1446,16 +1442,14 @@ static int update_pdp_prep(
                 rate = pdp_new[ds_idx] / interval;
                 break;
             case DST_GAUGE:
-               old_locale = setlocale(LC_NUMERIC, "C");
                 errno = 0;
                 pdp_new[ds_idx] =
-                    strtod(updvals[ds_idx + 1], &endptr) * interval;
+                    rrd_strtod(updvals[ds_idx + 1], &endptr) * interval;
                 if (errno) {
                     rrd_set_error("converting '%s' to float: %s",
                                   updvals[ds_idx + 1], rrd_strerror(errno));
                     return -1;
                 };
-                setlocale(LC_NUMERIC, old_locale);
                 if (endptr[0] != '\0') {
                     rrd_set_error
                         ("conversion of '%s' to float not complete: tail '%s'",
index d41af38ac13f5f784db60f5c3a87be95a557fc7d..671f4352b322e5f1bd982dbecd616414118e5aea 100644 (file)
@@ -18,6 +18,8 @@
 #include <fcntl.h>
 #endif
 
+#include "rrd_snprintf.h"
+
 int       rrd_xport(
     int,
     char **,
@@ -409,7 +411,6 @@ int rrd_graph_xport(image_desc_t *im) {
   grinfo_push(im, sprintf_alloc("graph_step"), RD_I_CNT, info);
 
   /* set locale */
-  char *old_locale = setlocale(LC_NUMERIC, "C");
 
   /* format it for output */
   int r=0;
@@ -438,8 +439,6 @@ int rrd_graph_xport(image_desc_t *im) {
   default:
     break;
   }
-  /* restore locale */
-  setlocale(LC_NUMERIC, old_locale);
   /* handle errors */
   if (r) {
     /* free legend */
@@ -567,9 +566,9 @@ int rrd_xport_format_sv(char sep, stringbuffer_t *buffer,image_desc_t *im,time_t
       rrd_value_t v=*ptr;ptr++;
       /* and print it */
       if (isnan(v)) {
-       snprintf(buf,255,"%c\"NaN\"",sep);
+        snprintf(buf,255,"%c\"NaN\"",sep);
       } else {
-       snprintf(buf,255,"%c\"%0.10e\"",sep,v);
+        rrd_snprintf(buf,255,"%c\"%0.10e\"",sep,v);
       }
       if (addToBuffer(buffer,buf,0)) { return 1;}
     }
@@ -666,11 +665,11 @@ int rrd_xport_format_xmljson(int flags,stringbuffer_t *buffer,image_desc_t *im,t
     snprintf(buf,sizeof(buf),"    \"%s\": %lld,\n",META_STEP_TAG,(long long int)step);
     addToBuffer(buffer,buf,0);
   } else {
-    snprintf(buf,sizeof(buf),"    <%s>%lld</%s>\n",META_STEP_TAG,(long long int)step,META_STEP_TAG); 
+    snprintf(buf,sizeof(buf),"    <%s>%lld</%s>\n",META_STEP_TAG,(long long int)step,META_STEP_TAG);
     addToBuffer(buffer,buf,0);
-    snprintf(buf,sizeof(buf),"    <%s>%lu</%s>\n",META_ROWS_TAG,row_cnt,META_ROWS_TAG); 
+    snprintf(buf,sizeof(buf),"    <%s>%lu</%s>\n",META_ROWS_TAG,row_cnt,META_ROWS_TAG);
     addToBuffer(buffer,buf,0);
-    snprintf(buf,sizeof(buf),"    <%s>%lu</%s>\n",META_COLS_TAG,col_cnt,META_COLS_TAG); 
+    snprintf(buf,sizeof(buf),"    <%s>%lu</%s>\n",META_COLS_TAG,col_cnt,META_COLS_TAG);
     addToBuffer(buffer,buf,0);
   }
   
@@ -756,11 +755,11 @@ int rrd_xport_format_xmljson(int flags,stringbuffer_t *buffer,image_desc_t *im,t
     }
     else {
       if (showtime) {
-       snprintf(buf,sizeof(buf),
-                "    <%s><%s>%s</%s>", DATA_ROW_TAG,COL_TIME_TAG, dbuf, COL_TIME_TAG);
+        snprintf(buf,sizeof(buf),
+                 "    <%s><%s>%s</%s>", DATA_ROW_TAG,COL_TIME_TAG, dbuf, COL_TIME_TAG);
       } else {
-       snprintf(buf,sizeof(buf),
-                "    <%s>", DATA_ROW_TAG);
+        snprintf(buf,sizeof(buf),
+                 "    <%s>", DATA_ROW_TAG);
       }
       addToBuffer(buffer,buf,0);
     }
@@ -771,7 +770,7 @@ int rrd_xport_format_xmljson(int flags,stringbuffer_t *buffer,image_desc_t *im,t
        if (isnan(newval) || isinf(newval)){
          addToBuffer(buffer,"null",0);                        
        } else {
-         snprintf(buf,sizeof(buf),"%0.10e",newval);
+          rrd_snprintf(buf,sizeof(buf),"%0.10e",newval);
          addToBuffer(buffer,buf,0);
        }
        if (j < col_cnt -1){
@@ -781,15 +780,15 @@ int rrd_xport_format_xmljson(int flags,stringbuffer_t *buffer,image_desc_t *im,t
       else {
        if (isnan(newval)) {
          if (enumds) {
-           snprintf(buf,sizeof(buf),"<%s%lu>NaN</%s%lu>", COL_DATA_TAG,j,COL_DATA_TAG,j);
+            snprintf(buf,sizeof(buf),"<%s%lu>NaN</%s%lu>", COL_DATA_TAG,j,COL_DATA_TAG,j);
          } else {
-           snprintf(buf,sizeof(buf),"<%s>NaN</%s>", COL_DATA_TAG,COL_DATA_TAG);
+            snprintf(buf,sizeof(buf),"<%s>NaN</%s>", COL_DATA_TAG,COL_DATA_TAG);
          }
        } else {
          if (enumds) {
-           snprintf(buf,sizeof(buf),"<%s%lu>%0.10e</%s%lu>", COL_DATA_TAG,j,newval,COL_DATA_TAG,j);
+            rrd_snprintf(buf,sizeof(buf),"<%s%lu>%0.10e</%s%lu>", COL_DATA_TAG,j,newval,COL_DATA_TAG,j);
          } else {
-           snprintf(buf,sizeof(buf),"<%s>%0.10e</%s>", COL_DATA_TAG,newval,COL_DATA_TAG);
+            rrd_snprintf(buf,sizeof(buf),"<%s>%0.10e</%s>", COL_DATA_TAG,newval,COL_DATA_TAG);
          }
        }
        addToBuffer(buffer,buf,0);
@@ -949,14 +948,14 @@ int rrd_xport_format_addprints(int flags,stringbuffer_t *buffer,image_desc_t *im
          ("bad format for PRINT in \"%s'", im->gdes[i].format);
        return -1;
       } else {
-       snprintf(dbuf,sizeof(dbuf), im->gdes[i].format, printval,"");
+        rrd_snprintf(dbuf,sizeof(dbuf), im->gdes[i].format, printval,"");
       }
       /* print */
       if (json) {
        escapeJSON(dbuf,sizeof(dbuf));
-       snprintf(buf,sizeof(buf),",\n        { \"%s\": \"%s\" }",usetag,dbuf);
+        snprintf(buf,sizeof(buf),",\n        { \"%s\": \"%s\" }",usetag,dbuf);
       } else {
-       snprintf(buf,sizeof(buf),"        <%s>%s</%s>\n",usetag,dbuf,usetag);
+        snprintf(buf,sizeof(buf),"        <%s>%s</%s>\n",usetag,dbuf,usetag);
       }
       addToBuffer(usebuffer,buf,0); }
       break;
@@ -964,9 +963,9 @@ int rrd_xport_format_addprints(int flags,stringbuffer_t *buffer,image_desc_t *im
       if (json) {
        strncpy(dbuf,im->gdes[i].legend,sizeof(dbuf));
        escapeJSON(dbuf,sizeof(dbuf));
-       snprintf(buf,sizeof(buf),",\n        { \"comment\": \"%s\" }",dbuf);
+        snprintf(buf,sizeof(buf),",\n        { \"comment\": \"%s\" }",dbuf);
       } else {
-       snprintf(buf,sizeof(buf),"        <comment>%s</comment>\n",im->gdes[i].legend);
+        snprintf(buf,sizeof(buf),"        <comment>%s</comment>\n",im->gdes[i].legend);
       }
       addToBuffer(&gprints,buf,0);
       break;
@@ -975,25 +974,25 @@ int rrd_xport_format_addprints(int flags,stringbuffer_t *buffer,image_desc_t *im
       /* I do not know why the legend is "spaced", but let us skip it */
       while(isspace(*entry)){entry++;}
       if (json) {
-       snprintf(buf,sizeof(buf),",\n        { \"line\": \"%s\" }",entry);
+        snprintf(buf,sizeof(buf),",\n        { \"line\": \"%s\" }",entry);
       } else {
-       snprintf(buf,sizeof(buf),"        <line>%s</line>\n",entry);
+        snprintf(buf,sizeof(buf),"        <line>%s</line>\n",entry);
       }
       addToBuffer(&gprints,buf,0);
       break;
     case GF_AREA:
       if (json) {
-       snprintf(buf,sizeof(buf),",\n        { \"area\": \"%s\" }",im->gdes[i].legend);
+        snprintf(buf,sizeof(buf),",\n        { \"area\": \"%s\" }",im->gdes[i].legend);
       } else {
-       snprintf(buf,sizeof(buf),"        <area>%s</area>\n",im->gdes[i].legend);
+        snprintf(buf,sizeof(buf),"        <area>%s</area>\n",im->gdes[i].legend);
       }
       addToBuffer(&gprints,buf,0);
       break;
     case GF_STACK:
       if (json) {
-       snprintf(buf,sizeof(buf),",\n        { \"stack\": \"%s\" }",im->gdes[i].legend);
+        snprintf(buf,sizeof(buf),",\n        { \"stack\": \"%s\" }",im->gdes[i].legend);
       } else {
-       snprintf(buf,sizeof(buf),"        <stack>%s</stack>\n",im->gdes[i].legend);
+        snprintf(buf,sizeof(buf),"        <stack>%s</stack>\n",im->gdes[i].legend);
       }
       addToBuffer(&gprints,buf,0);
       break;
@@ -1006,15 +1005,15 @@ int rrd_xport_format_addprints(int flags,stringbuffer_t *buffer,image_desc_t *im
       case TXA_JUSTIFIED: val="justified"; break;
       }
       if (json) {
-       snprintf(buf,sizeof(buf),",\n        { \"align\": \"%s\" }",val);
+        snprintf(buf,sizeof(buf),",\n        { \"align\": \"%s\" }",val);
       } else {
-       snprintf(buf,sizeof(buf),"        <align>%s</align>\n",val);
+        snprintf(buf,sizeof(buf),"        <align>%s</align>\n",val);
       }
       addToBuffer(&gprints,buf,0);
       break;
     case GF_HRULE:
       /* This does not work as expected - Tobi please help!!! */
-      snprintf(dbuf,sizeof(dbuf),"%0.10e",im->gdes[i].vf.val);
+      rrd_snprintf(dbuf,sizeof(dbuf),"%0.10e",im->gdes[i].vf.val);
       /* and output it */
       if (json) {
         snprintf(buf,sizeof(buf),",\n        { \"hrule\": \"%s\" }",dbuf);
@@ -1029,7 +1028,7 @@ int rrd_xport_format_addprints(int flags,stringbuffer_t *buffer,image_desc_t *im
        localtime_r(&im->gdes[i].xrule,&loc);
        strftime(dbuf,254,timefmt,&loc);
       } else {
-       snprintf(dbuf,254,"%lld",(long long int)im->gdes[i].vf.when);
+        snprintf(dbuf,254,"%lld",(long long int)im->gdes[i].vf.when);
       }
       /* and output it */
       if (json) {