Commit 9f4097cd authored by Juan Pablo Ugarte's avatar Juan Pablo Ugarte

GladePropertyDef: do not use setlocale in glade_dtostr()

Windows does not have setlocale() function
parent 24aef4fc
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment