Util: Fix Win32 build

This commit is contained in:
Jeffrey Pfau 2015-02-10 02:46:12 -08:00
parent 4b14b71861
commit f2c29bc8d6
3 changed files with 15 additions and 0 deletions

View File

@ -85,9 +85,15 @@ static bool _lookupFloatValue(const struct GBAConfig* config, const char* key, f
return false;
}
char* end;
#ifndef _WIN32
locale_t l = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
float value = strtof_l(charValue, &end, l);
freelocale(l);
#else
const char* oldlocale = setlocale(LC_NUMERIC, "C");
float value = strtof(charValue, &end);
setlocale(LC_NUMERIC, oldlocale);
#endif
if (*end) {
return false;
}

View File

@ -20,7 +20,10 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifndef _WIN32
#include <xlocale.h>
#endif
#define UNUSED(V) (void)(V)

View File

@ -79,9 +79,15 @@ void ConfigurationSetUIntValue(struct Configuration* configuration, const char*
void ConfigurationSetFloatValue(struct Configuration* configuration, const char* section, const char* key, float value) {
char charValue[16];
#ifndef _WIN32
locale_t l = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0);
snprintf_l(charValue, sizeof(charValue), l, "%.*g", FLT_DIG, value);
freelocale(l);
#else
const char* oldlocale = setlocale(LC_NUMERIC, "C");
snprintf(charValue, sizeof(charValue), "%.*g", FLT_DIG, value);
setlocale(LC_NUMERIC, oldlocale);
#endif
ConfigurationSetValue(configuration, section, key, charValue);
}