Decimal values rounded on save

Dirk Hohndel dirk at hohndel.org
Mon Sep 3 11:38:24 PDT 2012


On Sep 3, 2012, at 11:29 AM, Dirk Hohndel wrote:

> 
> On Sep 3, 2012, at 11:24 AM, Linus Torvalds wrote:
> 
>> On Mon, Sep 3, 2012 at 11:13 AM, Linus Torvalds
>> <torvalds at linux-foundation.org> wrote:
>>> 
>>> Damn. I guess we can do the usual
>>> 
>>>       setlocale(LC_NUMERIC,"C");
>>> 
>>> at the top of main(). Lazy, but the alternative is to do all the FP
>>> parsing by hand. We do *not* want the file to be locale-dependent.
>> 
>> Oh crist.
>> 
>> It's GTK. What a total piece of crap that library is.
> 
> I must have heard this before somewhere.
> Oh, right. I said that just a few weeks ago…
> 
>> The standard C rules are that the default locale is *always* the "C"
>> locale (exactly because nobody wants to have locales affect things
>> like parsing config files etc).
>> 
>> But gtk apparently does the
>> 
>>       setlocale(LC_ALL, "");
>> 
>> somewhere, which explains this braindamage.
>> 
>> And I can fix it, but then the sad part is that the gtk *visual* part
>> (where locales etc may well make sense!) will be broken.
>> 
>> Why the *hell* does GTK do LC_ALL? Using locale data for visual
>> elements is fine, but it is *not* fine to then mess things up and set
>> locales for the basic C library functions.
> 
> This can't be true. There's way too much software that uses gtk for this to be true.
> Ask on G+ - I'm sure there's a setting that makes it do the sane thing for basic C library functions…

Oh you are going to love this…

Look at http://developer.gnome.org/glib/2.28/glib-String-Utility-Functions.html

It seems that you should use THOSE functions instead…

g_ascii_strtoll ()
gint64 g_ascii_strtoll (const gchar *nptr, gchar **endptr, guint base);
Converts a string to a gint64 value. This function behaves like the standard strtoll() function does in the C locale. It does this without actually changing the current locale, since that would not be thread-safe.

This function is typically used when reading configuration files or other non-user input that should be locale independent. To handle input from the user you should normally use the locale-sensitive system strtoll() function.

If the correct value would cause overflow, G_MAXINT64 or G_MININT64 is returned, and ERANGE is stored in errno. If the base is outside the valid range, zero is returned, and EINVAL is stored in errno. If the string conversion fails, zero is returned, and endptr returns nptr (if endptr is non-NULL).


/D


More information about the subsurface mailing list