diff options
| author | L Pereira <l@tia.mat.br> | 2021-11-07 23:11:01 -0800 | 
|---|---|---|
| committer | L Pereira <l@tia.mat.br> | 2021-11-07 23:26:18 -0800 | 
| commit | 178a114c7a1a1774e5c95c72aa801a1a6006cbb9 (patch) | |
| tree | 6cdfcce857108baf3c272fa6088abfc5a46dce3e /modules | |
| parent | d4f76b1bad27dff472c4a9ecdf131edc1084b0db (diff) | |
Reformat CPU frequency using current locale
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/benchmark.c | 1 | ||||
| -rw-r--r-- | modules/benchmark/bench_results.c | 18 | 
2 files changed, 15 insertions, 4 deletions
| 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 <config.h>  #include <hardinfo.h>  #include <iconcache.h> 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 <stdlib.h> +#include <locale.h>  #include <inttypes.h>  #include <json-glib/json-glib.h> @@ -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) | 
