Util: Use proper locale for reading and writing float values
Jeffrey Pfau jeffrey@endrift.com
Tue, 10 Feb 2015 02:21:40 -0800
4 files changed,
10 insertions(+),
3 deletions(-)
M
CHANGES
→
CHANGES
@@ -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.c
→
src/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.h
→
src/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.c
→
src/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); }