diff options
author | Juan Pablo Ugarte <juanpablougarte@gmail.com> | 2020-10-07 10:24:40 -0300 |
---|---|---|
committer | Juan Pablo Ugarte <juanpablougarte@gmail.com> | 2020-10-09 16:04:14 -0300 |
commit | 7b10c43cbea1a61c700e98c7d6b6602057a021e0 (patch) | |
tree | 3c170f749e9276c75b20e66cfabe229d994dbf46 | |
parent | 9b3f55387f03920e1bf1cea9b7e9c911421cbb3e (diff) | |
download | glade-7b10c43cbea1a61c700e98c7d6b6602057a021e0.tar.gz |
GladePropertyDef: do not use setlocale in glade_dtostr()
Windows does not have setlocale() function
-rw-r--r-- | gladeui/glade-property-def.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/gladeui/glade-property-def.c b/gladeui/glade-property-def.c index 661c1735..c3ca5952 100644 --- a/gladeui/glade-property-def.c +++ b/gladeui/glade-property-def.c @@ -38,7 +38,6 @@ #include <string.h> #include <stdlib.h> #include <glib/gi18n-lib.h> -#include <locale.h> #include "glade.h" #include "glade-widget.h" @@ -458,34 +457,32 @@ glade_property_def_make_string_from_objects (GladePropertyDef * return string; } -static locale_t -get_C_locale (void) -{ - static gsize initialized = FALSE; - static locale_t C_locale = NULL; - - if (g_once_init_enter (&initialized)) - { - C_locale = newlocale (LC_ALL_MASK, "C", NULL); - g_once_init_leave (&initialized, TRUE); - } - - return C_locale; -} - static gchar * glade_dtostr (double number, gdouble epsilon) { - char *str = g_malloc (G_ASCII_DTOSTR_BUF_SIZE); + char *str = g_malloc (G_ASCII_DTOSTR_BUF_SIZE + 1); + char real_number[G_ASCII_DTOSTR_BUF_SIZE + 1]; + const gchar *decimal = NULL; int i; - for (i = 0; i <= 20; i++) + g_ascii_dtostr (str, G_ASCII_DTOSTR_BUF_SIZE, number); + g_ascii_dtostr (real_number, G_ASCII_DTOSTR_BUF_SIZE, number); + decimal = g_strstr_len (real_number, G_ASCII_DTOSTR_BUF_SIZE, "."); + + if (!decimal) + return str; + + decimal++; + + for (i = 1; i <= 20; i++) { + gint len = (decimal - real_number) + i; double rounded; - locale_t old_locale; - old_locale = uselocale (get_C_locale ()); - snprintf (str, G_ASCII_DTOSTR_BUF_SIZE, "%.*f", i, number); - uselocale (old_locale); + + /* add up to i decimal points */ + str[len] = real_number[len]; + str[len+1] = '\0'; + rounded = g_ascii_strtod (str, NULL); if (ABS (rounded - number) <= epsilon) |