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?)
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)
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);