From 178a114c7a1a1774e5c95c72aa801a1a6006cbb9 Mon Sep 17 00:00:00 2001 From: L Pereira Date: Sun, 7 Nov 2021 23:11:01 -0800 Subject: Reformat CPU frequency using current locale --- modules/benchmark.c | 1 + modules/benchmark/bench_results.c | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/benchmark.c b/modules/benchmark.c index 27ee9643..50ba7d2d 100644 --- a/modules/benchmark.c +++ b/modules/benchmark.c @@ -16,6 +16,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#define _GNU_SOURCE #include #include #include diff --git a/modules/benchmark/bench_results.c b/modules/benchmark/bench_results.c index 0f3533b8..5403d963 100644 --- a/modules/benchmark/bench_results.c +++ b/modules/benchmark/bench_results.c @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include +#include #include #include @@ -325,6 +327,16 @@ static gchar *json_get_string_dup(JsonObject *obj, const gchar *key) return g_strdup(json_get_string(obj, key)); } +static double parse_frequency(const char *freq) +{ + static locale_t locale; + + if (!locale) + locale = newlocale(LC_NUMERIC_MASK, "C", NULL); + + return strtod_l(freq, NULL, locale); +} + static void append_cpu_config(JsonObject *object, const gchar *member_name, JsonNode *member_node, @@ -335,10 +347,8 @@ static void append_cpu_config(JsonObject *object, if (output->len) g_string_append(output, ", "); - // FIXME: need to parse member_name as float in the C locale, - // and re-format that as float in the current locale - g_string_append_printf(output, "%ldx %s %s", json_node_get_int(member_node), - member_name, _("MHz")); + g_string_append_printf(output, "%ldx %.2f %s", json_node_get_int(member_node), + parse_frequency(member_name), _("MHz")); } static gchar *get_cpu_config(JsonObject *machine) -- cgit v1.2.3