mirror of https://github.com/mgba-emu/mgba.git
Util: Use proper locale for reading and writing float values
This commit is contained in:
parent
9c3e16925b
commit
4b14b71861
1
CHANGES
1
CHANGES
|
@ -51,6 +51,7 @@ Misc:
|
|||
- 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:
|
||||
|
|
|
@ -85,7 +85,9 @@ static bool _lookupFloatValue(const struct GBAConfig* config, const char* key, f
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <xlocale.h>
|
||||
|
||||
#define UNUSED(V) (void)(V)
|
||||
|
||||
|
|
|
@ -78,8 +78,10 @@ void ConfigurationSetUIntValue(struct Configuration* configuration, const char*
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue