diff --git a/common/os_calls.c b/common/os_calls.c index 234e01c7..c58ebd60 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -136,7 +136,21 @@ g_init(const char *app_name) WSAStartup(2, &wsadata); #endif - setlocale(LC_CTYPE, ""); + + /* In order to get g_mbstowcs and g_wcstombs to work properly with + UTF-8 non-ASCII characters, LC_CTYPE cannot be "C" or blank. + To select UTF-8 encoding without specifying any countries/languages, + "C.UTF-8" is used but provided in few systems. + + See also: https://sourceware.org/glibc/wiki/Proposals/C.UTF-8 */ + char *lc_ctype; + lc_ctype = setlocale(LC_CTYPE, "C.UTF-8"); + if (lc_ctype == NULL) + { + /* use en_US.UTF-8 instead if not available */ + setlocale(LC_CTYPE, "en_US.UTF-8"); + } + g_mk_temp_dir(app_name); }