summaryrefslogtreecommitdiff
path: root/src/shared/json.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-07-05 16:27:09 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-07-05 22:14:50 +0200
commit93258c7d72fae23c9f8103c98dd0e79a24838e26 (patch)
tree4e85e185102a5dd0c9ed427ad060c9638cb873c9 /src/shared/json.c
parent977ad21b5b8f6323515297bd8995dcaaca0905df (diff)
downloadsystemd-93258c7d72fae23c9f8103c98dd0e79a24838e26.tar.gz
json: actually use numeric C locale we just allocated
This fixes formatting of JSON real values, and uses C locale for them. It's kinda interesting that this wasn't noticed before: the C locale object we allocated was not used, hence doing the dance had zero effect. This makes "test-varlink" pass again on systems with non-C locale. (My guess: noone noticed this because "long double" was used before by the JSON code and that had no locale supporting printer or so?)
Diffstat (limited to 'src/shared/json.c')
-rw-r--r--src/shared/json.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/shared/json.c b/src/shared/json.c
index bcc109abc2..13bc44a9ed 100644
--- a/src/shared/json.c
+++ b/src/shared/json.c
@@ -1545,7 +1545,7 @@ static int json_format(FILE *f, JsonVariant *v, JsonFormatFlags flags, const cha
switch (json_variant_type(v)) {
case JSON_VARIANT_REAL: {
- locale_t loc;
+ locale_t loc, old_loc;
loc = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
if (loc == (locale_t) 0)
@@ -1554,7 +1554,9 @@ static int json_format(FILE *f, JsonVariant *v, JsonFormatFlags flags, const cha
if (flags & JSON_FORMAT_COLOR)
fputs(ansi_highlight_blue(), f);
+ old_loc = uselocale(loc);
fprintf(f, "%.*e", DECIMAL_DIG, json_variant_real(v));
+ uselocale(old_loc);
if (flags & JSON_FORMAT_COLOR)
fputs(ANSI_NORMAL, f);