Util: Check for SETLOCALE too

This commit is contained in:
Jeffrey Pfau 2015-07-05 13:05:09 -07:00
parent 32cb7bfcdc
commit d9778a98d4
2 changed files with 12 additions and 2 deletions

View File

@ -228,6 +228,7 @@ endif()
check_function_exists(newlocale HAVE_NEWLOCALE)
check_function_exists(freelocale HAVE_FREELOCALE)
check_function_exists(uselocale HAVE_USELOCALE)
check_function_exists(setlocale HAVE_SETLOCALE)
if(HAVE_STRDUP)
add_definitions(-DHAVE_STRDUP)
@ -247,6 +248,9 @@ if(HAVE_NEWLOCALE AND HAVE_FREELOCALE AND HAVE_USELOCALE)
endif()
endif()
if(HAVE_SETLOCALE)
add_definitions(-DHAVE_SETLOCALE)
endif()
# Features
set(DEBUGGER_SRC ${CMAKE_SOURCE_DIR}/src/debugger/debugger.c ${CMAKE_SOURCE_DIR}/src/debugger/memory-debugger.c)

View File

@ -15,11 +15,14 @@ int ftostr_l(char* restrict str, size_t size, float f, locale_t locale) {
int res = snprintf(str, size, "%*.g", FLT_DIG, f);
uselocale(old);
return res;
#else
#elif defined(HAVE_SETLOCALE)
char* old = setlocale(LC_NUMERIC, locale);
int res = snprintf(str, size, "%*.g", FLT_DIG, f);
setlocale(LC_NUMERIC, old);
return res;
#else
UNUSED(locale);
return snprintf(str, size, "%*.g", FLT_DIG, f);
#endif
}
@ -30,11 +33,14 @@ float strtof_l(const char* restrict str, char** restrict end, locale_t locale) {
float res = strtof(str, end);
uselocale(old);
return res;
#else
#elif defined(HAVE_SETLOCALE)
char* old = setlocale(LC_NUMERIC, locale);
float res = strtof(str, end);
setlocale(LC_NUMERIC, old);
return res;
#else
UNUSED(locale);
return strtof(str, end);
#endif
}
#endif