From: oetiker Date: Wed, 8 Sep 2010 12:15:13 +0000 (+0000) Subject: fix use of setlocale all over the place ... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=1f472620354603bd3bf2fdee30e2dd70dea7a4f1;p=rrdtool.git fix use of setlocale all over the place ... - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); the original version never restored the locale since it held a copy of the new locale and not the old one despite the name. bug found by Pawe? 'Reef' Polewicz git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@2127 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/src/rrd_create.c b/src/rrd_create.c index 2a0a143..c8996ce 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -571,7 +571,8 @@ void parseGENERIC_DS( &(rrd -> ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt), minstr,maxstr); */ - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); if (sscanf(def, "%lu:%18[^:]:%18[^:]", &(rrd->ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt), minstr, maxstr) == 3) { diff --git a/src/rrd_dump.c b/src/rrd_dump.c index ccc5349..bdd8a52 100644 --- a/src/rrd_dump.c +++ b/src/rrd_dump.c @@ -103,7 +103,8 @@ int rrd_dump_cb_r( return (-1); } - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); if (opt_header == 1) { diff --git a/src/rrd_graph.c b/src/rrd_graph.c index d15ce3d..898b6ff 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -3991,15 +3991,18 @@ rrd_info_t *rrd_graph_v( 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"); + old_locale = setlocale(LC_NUMERIC, NULL); + 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"); @@ -4007,6 +4010,7 @@ 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); diff --git a/src/rrd_rpncalc.c b/src/rrd_rpncalc.c index 80eb144..c1a61c2 100644 --- a/src/rrd_rpncalc.c +++ b/src/rrd_rpncalc.c @@ -297,7 +297,8 @@ rpnp_t *rpn_parse( char vname[MAX_VNAME_LEN + 10]; char *old_locale; - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); rpnp = NULL; expr = (char *) expr_const; diff --git a/src/rrd_tool.c b/src/rrd_tool.c index 45296c8..cc2aede 100644 --- a/src/rrd_tool.c +++ b/src/rrd_tool.c @@ -714,7 +714,8 @@ int HandleInputLine( if (rrd_xport (argc - 1, &argv[1], &xxsize, &start, &end, &step, &col_cnt, &legend_v, &data) != -1) { - char *old_locale = setlocale(LC_NUMERIC, "C"); + char *old_locale = setlocale(LC_NUMERIC,NULL); + setlocale(LC_NUMERIC, "C"); row_cnt = (end - start) / step; ptr = data; printf("\n\n", diff --git a/src/rrd_tune.c b/src/rrd_tune.c index 80c2de0..52651fd 100644 --- a/src/rrd_tune.c +++ b/src/rrd_tune.c @@ -126,7 +126,8 @@ int rrd_tune( optcnt++; switch (opt) { case 'h': - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); if ((matches = sscanf(optarg, DS_NAM_FMT ":%ld", ds_nam, &heartbeat)) != 2) { @@ -146,7 +147,8 @@ int rrd_tune( break; case 'i': - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + 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"); @@ -168,7 +170,8 @@ int rrd_tune( break; case 'a': - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + 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"); diff --git a/src/rrd_update.c b/src/rrd_update.c index a06b404..563d7ac 100644 --- a/src/rrd_update.c +++ b/src/rrd_update.c @@ -977,7 +977,8 @@ 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"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); errno = 0; tmp = strtod(updvals[0], 0); if (errno > 0) { @@ -1089,7 +1090,8 @@ static int update_pdp_prep( } break; case DST_ABSOLUTE: - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); errno = 0; pdp_new[ds_idx] = strtod(updvals[ds_idx + 1], &endptr); if (errno > 0) { @@ -1107,7 +1109,8 @@ static int update_pdp_prep( rate = pdp_new[ds_idx] / interval; break; case DST_GAUGE: - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); errno = 0; pdp_new[ds_idx] = strtod(updvals[ds_idx + 1], &endptr) * interval;