summaryrefslogtreecommitdiff
path: root/json_tokener.c
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2012-12-13 09:47:33 +0100
committerRemi Collet <fedora@famillecollet.com>2012-12-13 09:47:33 +0100
commita01b659ace168d85a3e9e47848eaaba2bea31078 (patch)
treef2c68350ea09f440e921b04a513de523e5050e90 /json_tokener.c
parent16a4a32e294e80ca8c89ec83e62baa0c59947ac9 (diff)
move locale change to be global for perf
Diffstat (limited to 'json_tokener.c')
-rw-r--r--json_tokener.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/json_tokener.c b/json_tokener.c
index 85c530b..63bb41b 100644
--- a/json_tokener.c
+++ b/json_tokener.c
@@ -31,6 +31,10 @@
#include "json_tokener.h"
#include "json_util.h"
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif /* HAVE_LOCALE_H */
+
#if !HAVE_STRDUP && defined(_MSC_VER)
/* MSC has the version as _strdup */
# define strdup _strdup
@@ -227,6 +231,13 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
{
struct json_object *obj = NULL;
char c = '\1';
+#ifdef HAVE_SETLOCALE
+ char *oldlocale=NULL, *tmplocale;
+
+ tmplocale = setlocale(LC_NUMERIC, NULL);
+ if (tmplocale) oldlocale = strdup(tmplocale);
+ setlocale(LC_NUMERIC, "C");
+#endif
tok->char_offset = 0;
tok->err = json_tokener_success;
@@ -724,6 +735,11 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
tok->err = json_tokener_error_parse_eof;
}
+#ifdef HAVE_SETLOCALE
+ setlocale(LC_NUMERIC, oldlocale);
+ if (oldlocale) free(oldlocale);
+#endif
+
if (tok->err == json_tokener_success)
{
json_object *ret = json_object_get(current);