Code

make sure all ascii to float parsing uses LC_NUMERIC = C so that we do not stuble...
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 18 Jul 2007 21:47:26 +0000 (21:47 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 18 Jul 2007 21:47:26 +0000 (21:47 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1157 a5681a0c-68f1-0310-ab6d-d61299d08faa

program/src/rrd_create.c
program/src/rrd_graph.c
program/src/rrd_rpncalc.c
program/src/rrd_tune.c
program/src/rrd_update.c

index a3b73ca5f734782e62fa061fcebafa0f618a76ac..0e2f82c14150e8d39ef28cd0f42dbed1192cdaf2 100644 (file)
@@ -4,6 +4,8 @@
  * rrd_create.c  creates new rrds
  *****************************************************************************/
 
+#include <locale.h>
+
 #include "rrd_tool.h"
 #include "rrd_rpncalc.h"
 #include "rrd_hw.h"
@@ -512,7 +514,7 @@ void parseGENERIC_DS(
     int ds_idx)
 {
     char      minstr[DS_NAM_SIZE], maxstr[DS_NAM_SIZE];
-
+    char *old_locale;
     /*
        int temp;
 
@@ -520,6 +522,7 @@ void parseGENERIC_DS(
        &(rrd -> ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt),
        minstr,maxstr);
      */
+    old_locale = setlocale(LC_NUMERIC,"C");
     if (sscanf(def, "%lu:%18[^:]:%18[^:]",
                &(rrd->ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt),
                minstr, maxstr) == 3) {
@@ -538,11 +541,13 @@ void parseGENERIC_DS(
             rrd->ds_def[ds_idx].par[DS_min_val].u_val
             >= rrd->ds_def[ds_idx].par[DS_max_val].u_val) {
             rrd_set_error("min must be less than max in DS definition");
+            setlocale(LC_NUMERIC,old_locale);
             return;
         }
     } else {
         rrd_set_error("failed to parse data source %s", def);
     }
+    setlocale(LC_NUMERIC,old_locale);
 }
 
 /* Create the CF_DEVPREDICT, CF_DEVSEASONAL, CF_SEASONAL, and CF_FAILURES RRAs
index f7ea57286a4112250d9cf0e92f471e2cbd73614d..6b8a46dbf1f8753edbfd234337c23e9919ebae01 100644 (file)
@@ -3721,6 +3721,7 @@ void rrd_graph_options(
     long      long_tmp;
     struct rrd_time_value start_tv, end_tv;
     long unsigned int color;
+    char *old_locale = "";
 
     /* defines for long options without a short equivalent. should be bytes,
        and may not collide with (the ASCII value of) short options */
@@ -3780,7 +3781,6 @@ void rrd_graph_options(
         int       option_index = 0;
         int       opt;
         int       col_start, col_end;
-
         opt = getopt_long(argc, argv,
                           "s:e:x:y:v:w:h:D:iu:l:rb:oc:n:m:t:f:a:I:zgjFYAMEX:L:S:T:NR:B:W:",
                           long_options, &option_index);
@@ -3816,6 +3816,7 @@ void rrd_graph_options(
         case LONGOPT_UNITS_SI:
             if (im->extra_flags & FORCE_UNITS) {
                 rrd_set_error("--units can only be used once!");
+                setlocale(LC_NUMERIC,old_locale);
                 return;
             }
             if (strcmp(optarg, "si") == 0)
@@ -3833,10 +3834,14 @@ void rrd_graph_options(
             im->forceleftspace = 1;
             break;
         case 'T':
+            old_locale = setlocale(LC_NUMERIC,"C");
             im->tabwidth = atof(optarg);
+            setlocale(LC_NUMERIC,old_locale);
             break;
         case 'S':
+            old_locale = setlocale(LC_NUMERIC,"C");
             im->step = atoi(optarg);
+            setlocale(LC_NUMERIC,old_locale);
             break;
         case 'N':
             im->gridfit = 0;
@@ -3896,8 +3901,9 @@ void rrd_graph_options(
                 im->draw_y_grid = 0;
                 break;
             };
-
+            old_locale=setlocale(LC_NUMERIC,"C");           
             if (sscanf(optarg, "%lf:%d", &im->ygridstep, &im->ylabfact) == 2) {
+                setlocale(LC_NUMERIC,old_locale);
                 if (im->ygridstep <= 0) {
                     rrd_set_error("grid step must be > 0");
                     return;
@@ -3906,6 +3912,7 @@ void rrd_graph_options(
                     return;
                 }
             } else {
+                setlocale(LC_NUMERIC,old_locale);
                 rrd_set_error("invalid y-grid format");
                 return;
             }
@@ -3915,10 +3922,14 @@ void rrd_graph_options(
             im->ylegend[150] = '\0';
             break;
         case 'u':
+            old_locale=setlocale(LC_NUMERIC,"C");           
             im->maxval = atof(optarg);
+            setlocale(LC_NUMERIC,old_locale);
             break;
         case 'l':
+            old_locale=setlocale(LC_NUMERIC,"C");           
             im->minval = atof(optarg);
+            setlocale(LC_NUMERIC,old_locale);
             break;
         case 'b':
             im->base = atol(optarg);
@@ -4016,10 +4027,11 @@ void rrd_graph_options(
             char      prop[15];
             double    size = 1;
             char      font[1024] = "";
-
+            old_locale = setlocale(LC_NUMERIC,"C");
             if (sscanf(optarg, "%10[A-Z]:%lf:%1000s", prop, &size, font) >= 2) {
                 int       sindex, propidx;
-
+    
+                setlocale(LC_NUMERIC,old_locale);
                 if ((sindex = text_prop_conv(prop)) != -1) {
                     for (propidx = sindex; propidx < TEXT_PROP_LAST;
                          propidx++) {
@@ -4036,14 +4048,17 @@ void rrd_graph_options(
                     rrd_set_error("invalid fonttag '%s'", prop);
                     return;
                 }
-            } else {
+           } else {
+                setlocale(LC_NUMERIC,old_locale);
                 rrd_set_error("invalid text property format");
                 return;
             }
             break;
         }
         case 'm':
+            old_locale=setlocale(LC_NUMERIC,"C");           
             im->zoom = atof(optarg);
+            setlocale(LC_NUMERIC,old_locale);
             if (im->zoom <= 0.0) {
                 rrd_set_error("zoom factor must be > 0");
                 return;
@@ -4243,9 +4258,12 @@ int vdef_parse(
     double    param;
     char      func[30];
     int       n;
+    char      *old_locale;
 
     n = 0;
+    old_locale = setlocale(LC_NUMERIC,"C");
     sscanf(str, "%le,%29[A-Z]%n", &param, func, &n);
+    setlocale(LC_NUMERIC,old_locale);
     if (n == (int) strlen(str)) {   /* matched */
         ;
     } else {
index 7953320f084820349345a38e55b0fba2d8cfdb8d..2fc6ca77ee2cdd6598a914f888e34a1849ab48f3 100644 (file)
@@ -8,6 +8,7 @@
 #include "rrd_rpncalc.h"
 #include "rrd_graph.h"
 #include <limits.h>
+#include <locale.h>
 
 short     addop2str(
     enum op_en op,
@@ -287,6 +288,8 @@ 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");
 
     rpnp = NULL;
     expr = (char *) expr_const;
@@ -294,9 +297,10 @@ 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)
                  && (expr[pos] == ',')) {
             rpnp[steps].op = OP_NUMBER;
@@ -306,8 +310,7 @@ rpnp_t   *rpn_parse(
         else if (strncmp(expr, #VVV, strlen(#VVV))==0 && ( expr[strlen(#VVV)] == ',' || expr[strlen(#VVV)] == '\0' )){ \
             rpnp[steps].op = VV; \
             expr+=strlen(#VVV); \
-       }
-
+       }
 
 #define match_op_param(VV,VVV) \
         else if (sscanf(expr, #VVV "(" DEF_NAM_FMT ")",vname) == 1) { \
@@ -379,19 +382,23 @@ rpnp_t   *rpn_parse(
         }
 
         else {
+            setlocale(LC_NUMERIC,old_locale);
             free(rpnp);
             return NULL;
         }
+
         if (*expr == 0)
             break;
         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 f675c8b24d92ec9f5524a696b67f543ca629d2dd..f5bea46a6daf8b16e89706f3726d6268686ad581 100644 (file)
@@ -42,6 +42,7 @@
 #include "rrd_tool.h"
 #include "rrd_rpncalc.h"
 #include "rrd_hw.h"
+#include <locale.h>
 
 int       set_hwarg(
     rrd_t *rrd,
@@ -104,7 +105,7 @@ int rrd_tune(
     while (1) {
         int       option_index = 0;
         int       opt;
-
+        char *old_locale = "";
         opt = getopt_long(argc, argv, "h:i:a:d:r:p:n:w:f:x:y:z:v:b:",
                           long_options, &option_index);
         if (opt == EOF)
@@ -113,14 +114,17 @@ int rrd_tune(
         optcnt++;
         switch (opt) {
         case 'h':
+            old_locale = setlocale(LC_NUMERIC,"C");
             if ((matches =
                  sscanf(optarg, DS_NAM_FMT ":%ld", ds_nam,
                         &heartbeat)) != 2) {
                 rrd_set_error("invalid arguments for heartbeat");
                 rrd_free(&rrd);
                 rrd_close(rrd_file);
+                setlocale(LC_NUMERIC,old_locale);
                 return -1;
             }
+            setlocale(LC_NUMERIC,old_locale);
             if ((ds = ds_match(&rrd, ds_nam)) == -1) {
                 rrd_free(&rrd);
                 rrd_close(rrd_file);
@@ -130,13 +134,16 @@ int rrd_tune(
             break;
 
         case 'i':
+            old_locale = setlocale(LC_NUMERIC,"C");
             if ((matches =
                  sscanf(optarg, DS_NAM_FMT ":%lf", ds_nam, &min)) < 1) {
                 rrd_set_error("invalid arguments for minimum ds value");
                 rrd_free(&rrd);
                 rrd_close(rrd_file);
+                setlocale(LC_NUMERIC,old_locale);
                 return -1;
             }
+            setlocale(LC_NUMERIC,old_locale);
             if ((ds = ds_match(&rrd, ds_nam)) == -1) {
                 rrd_free(&rrd);
                 rrd_close(rrd_file);
@@ -149,13 +156,16 @@ int rrd_tune(
             break;
 
         case 'a':
+            old_locale = setlocale(LC_NUMERIC,"C");
             if ((matches =
                  sscanf(optarg, DS_NAM_FMT ":%lf", ds_nam, &max)) < 1) {
                 rrd_set_error("invalid arguments for maximum ds value");
                 rrd_free(&rrd);
                 rrd_close(rrd_file);
+                setlocale(LC_NUMERIC,old_locale);
                 return -1;
             }
+            setlocale(LC_NUMERIC,old_locale);
             if ((ds = ds_match(&rrd, ds_nam)) == -1) {
                 rrd_free(&rrd);
                 rrd_close(rrd_file);
index 9a1f32dafc90e1e1dec629da0c1d132eb4f92801..45971a4b5898a3a9a5007c5c304458eda0985c11 100644 (file)
@@ -14,6 +14,8 @@
 #include <io.h>
 #endif
 
+#include <locale.h>
+
 #include "rrd_hw.h"
 #include "rrd_rpncalc.h"
 
@@ -500,8 +502,10 @@ int _rrd_update(
             current_time_usec = tmp_time.tv_usec;
         } else {
             double    tmp;
-
+            char    *old_locale;
+            old_locale = setlocale(LC_NUMERIC,"C");
             tmp = strtod(updvals[0], 0);
+            setlocale(LC_NUMERIC,old_locale);
             current_time = floor(tmp);
             current_time_usec =
                 (long) ((tmp - (double) current_time) * 1000000.0);
@@ -593,6 +597,7 @@ int _rrd_update(
                 (dst_idx != DST_CDEF) &&
                 rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt >= interval) {
                 double    rate = DNAN;
+                char    *old_locale;
 
                 /* the data source type defines how to process the data */
                 /* pdp_new contains rate * time ... eg the bytes
@@ -636,8 +641,10 @@ int _rrd_update(
                     }
                     break;
                 case DST_ABSOLUTE:
+                    old_locale = setlocale(LC_NUMERIC,"C");
                     errno = 0;
                     pdp_new[i] = strtod(updvals[i + 1], &endptr);
+                    setlocale(LC_NUMERIC,old_locale);
                     if (errno > 0) {
                         rrd_set_error("converting '%s' to float: %s",
                                       updvals[i + 1], rrd_strerror(errno));
@@ -653,7 +660,9 @@ int _rrd_update(
                     break;
                 case DST_GAUGE:
                     errno = 0;
+                    old_locale = setlocale(LC_NUMERIC,"C");
                     pdp_new[i] = strtod(updvals[i + 1], &endptr) * interval;
+                    setlocale(LC_NUMERIC,old_locale);
                     if (errno > 0) {
                         rrd_set_error("converting '%s' to float: %s",
                                       updvals[i + 1], rrd_strerror(errno));