add check for setlocale in C library

Microsoft CRT and glibc have setlocale, but bionic doesn't
This commit is contained in:
tildearrow 2024-06-09 04:27:48 -05:00
parent d6783f8e2c
commit 4e14c9f59c
3 changed files with 26 additions and 0 deletions

View file

@ -1039,6 +1039,17 @@ if (NOT WIN32)
endif()
if (WITH_LOCALE)
try_compile(HAVE_SETLOCALE ${CMAKE_BINARY_DIR}/check SOURCES ${CMAKE_SOURCE_DIR}/src/check/check_setlocale.c)
if (HAVE_SETLOCALE)
list(APPEND DEPENDENCIES_DEFINES HAVE_SETLOCALE)
message(STATUS "setlocale() found")
else()
if (NOT USE_MOMO)
message(FATAL_ERROR "setlocale() is not defined! This means the C library in your system does not support locale at all. Try enabling USE_MOMO.")
else()
message(STATUS "setlocale() is not defined")
endif()
endif()
if (USE_MOMO)
list(APPEND ENGINE_SOURCES src/momo/momo.c)
list(APPEND DEPENDENCIES_DEFINES HAVE_LOCALE)

View file

@ -0,0 +1,7 @@
#include <locale.h>
int main(int, char**) {
setlocale(LC_CTYPE,"");
setlocale(LC_MESSAGES,"");
return 0;
}

View file

@ -510,6 +510,7 @@ int main(int argc, char** argv) {
#ifdef HAVE_LOCALE
String reqLocale=e.getConfString("locale","");
const char* localeRet=NULL;
#ifdef HAVE_SETLOCALE
if ((localeRet=setlocale(LC_CTYPE,reqLocale.c_str()))==NULL) {
logE("could not set locale (CTYPE)!");
} else {
@ -530,6 +531,13 @@ int main(int argc, char** argv) {
}
#endif
}
#else
if ((localeRet=momo_setlocale(LC_MESSAGES,reqLocale.c_str()))==NULL) {
logV("Momo: could not set locale!");
} else {
logV("locale: %s",localeRet);
}
#endif
if ((localeRet=TA_BINDTEXTDOMAIN("furnace","locale"))==NULL) {
if ((localeRet=TA_BINDTEXTDOMAIN("furnace","../po/locale"))==NULL) {