From 4e14c9f59c1db28edac9c1936ccdccb1e3502eec Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 9 Jun 2024 04:27:48 -0500 Subject: [PATCH] add check for setlocale in C library Microsoft CRT and glibc have setlocale, but bionic doesn't --- CMakeLists.txt | 11 +++++++++++ src/check/check_setlocale.c | 7 +++++++ src/main.cpp | 8 ++++++++ 3 files changed, 26 insertions(+) create mode 100644 src/check/check_setlocale.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 38aaa63b8..4d2fe3f3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/check/check_setlocale.c b/src/check/check_setlocale.c new file mode 100644 index 000000000..394dce7d6 --- /dev/null +++ b/src/check/check_setlocale.c @@ -0,0 +1,7 @@ +#include + +int main(int, char**) { + setlocale(LC_CTYPE,""); + setlocale(LC_MESSAGES,""); + return 0; +} diff --git a/src/main.cpp b/src/main.cpp index 4348901af..763508caa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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) {