all repos — mgba @ 4b14b71861b40026987d3b11024591bece1435eb

mGBA Game Boy Advance Emulator

Util: Use proper locale for reading and writing float values
Jeffrey Pfau jeffrey@endrift.com
Tue, 10 Feb 2015 02:21:40 -0800
commit

4b14b71861b40026987d3b11024591bece1435eb

parent

9c3e16925b88d12f2acfb8c0766ba90709c2cfd2

4 files changed, 10 insertions(+), 3 deletions(-)

jump to
M CHANGESCHANGES

@@ -51,6 +51,7 @@ - GBA: Add API for getting Configuration structs for overrides and input

- GBA: Refactor gba-sensors and gba-gpio into gba-hardware - GBA: Refactor gba directory, dropping gba- prefix and making supervisor directory - Debugger: Add support for soft breakpoints + - Util: Use proper locale for reading and writing float values 0.1.1: (2015-01-24) Bugfixes:
M src/gba/supervisor/config.csrc/gba/supervisor/config.c

@@ -85,7 +85,9 @@ if (!charValue) {

return false; } char* end; - float value = strtof(charValue, &end); + locale_t l = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0); + float value = strtof_l(charValue, &end, l); + freelocale(l); if (*end) { return false; }
M src/util/common.hsrc/util/common.h

@@ -10,6 +10,7 @@ #include <ctype.h>

#include <fcntl.h> #include <inttypes.h> #include <limits.h> +#include <locale.h> #include <math.h> #include <stdarg.h> #include <stdbool.h>

@@ -19,6 +20,7 @@ #include <stdio.h>

#include <stdlib.h> #include <string.h> #include <unistd.h> +#include <xlocale.h> #define UNUSED(V) (void)(V)
M src/util/configuration.csrc/util/configuration.c

@@ -78,8 +78,10 @@ ConfigurationSetValue(configuration, section, key, charValue);

} void ConfigurationSetFloatValue(struct Configuration* configuration, const char* section, const char* key, float value) { - char charValue[FLT_DIG + 7]; - sprintf(charValue, "%.*g", FLT_DIG, value); + char charValue[16]; + locale_t l = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0); + snprintf_l(charValue, sizeof(charValue), l, "%.*g", FLT_DIG, value); + freelocale(l); ConfigurationSetValue(configuration, section, key, charValue); }