diff --git a/inc/lektor/internal/os.h b/inc/lektor/internal/os.h index e2742e53186662892f8add8f055a5c96ea052afc..c2f6d62dfb69988a4534c286e1ff4d336161e88f 100644 --- a/inc/lektor/internal/os.h +++ b/inc/lektor/internal/os.h @@ -6,6 +6,7 @@ extern "C" { #include <inttypes.h> #include <locale.h> +#include <langinfo.h> #include <memory.h> #include <regex.h> #include <stddef.h> diff --git a/src/main/lkt.c b/src/main/lkt.c index e62a532e6022c6ec51baa13745dc49ee2752e1bb..b673e2c5584abae578243267ad4ffcba0ac6deb1 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -1381,7 +1381,13 @@ main(int argc, const char **argv) lkt_install_segv_handler(); lkt_set_log_level(LOG_LEVEL_INFO); cmd_set_executable_name("lkt"); - assert(NULL != setlocale(LC_ALL, "en_US.UTF-8")); /* BECAUSE! */ + + /* Enforce some locals */ + RETURN_UNLESS(setlocale(LC_ALL, ""), "Failed to set LC_ALL to UTF-8", 1); + RETURN_UNLESS(setlocale(LC_CTYPE, ""), "Failed to set LC_CTYPE", 1); + RETURN_UNLESS(setlocale(LC_NUMERIC, ""), "Failed to set LC_NUMERIC for mpv", 1); + RETURN_UNLESS(STR_MATCH(nl_langinfo(CODESET), "UTF-8"), "Your locale is not set to an UTF-8 one. " "Consider using en_US.UTF-8 or fr_FR.UTF-8!", 1); + if (signal(SIGPIPE, sigpipe__)) LOG_ERROR("SYS", "Failed to install handler for SIGPIPE signal (you may be using php...)"); diff --git a/src/main/luka.c b/src/main/luka.c index 20581f5938ee70211ffe9868d25de15e8ce6b3f4..43f20460d587e84f10023fdedd0b393745afb3d0 100644 --- a/src/main/luka.c +++ b/src/main/luka.c @@ -455,7 +455,13 @@ main(const int argc, const char **argv) lkt_set_log_level(LOG_LEVEL_ERROR); lkt_segv_quiet(); lkt_install_segv_handler(); - assert(NULL != setlocale(LC_ALL, "en_US.UTF-8")); /* BECAUSE! */ + + /* Enforce some locals */ + RETURN_UNLESS(setlocale(LC_ALL, ""), "Failed to set LC_ALL to UTF-8", 1); + RETURN_UNLESS(setlocale(LC_CTYPE, ""), "Failed to set LC_CTYPE", 1); + RETURN_UNLESS(setlocale(LC_NUMERIC, ""), "Failed to set LC_NUMERIC for mpv", 1); + RETURN_UNLESS(STR_MATCH(nl_langinfo(CODESET), "UTF-8"), "Your locale is not set to an UTF-8 one. " "Consider using en_US.UTF-8 or fr_FR.UTF-8!", 1); + if (signal(SIGPIPE, __sigpipe)) LOG_ERROR("SYS", "Failed to install handler for SIGPIPE signal (you may be using php...)"); diff --git a/src/main/server.c b/src/main/server.c index 480473a71934b8b9e7b22789907046576f48310e..f795ff028d05dc65c3ac01c7c7e59df64b505c79 100644 --- a/src/main/server.c +++ b/src/main/server.c @@ -45,9 +45,10 @@ main(int argc, char *argv[]) REG_END() /* Enforce some locals */ - RETURN_UNLESS(setlocale(LC_ALL, "en_US.UTF-8"), "Failed to set LC_ALL to UTF-8", 1); + RETURN_UNLESS(setlocale(LC_ALL, ""), "Failed to set LC_ALL to UTF-8", 1); RETURN_UNLESS(setlocale(LC_CTYPE, ""), "Failed to set LC_CTYPE", 1); - RETURN_UNLESS(setlocale(LC_NUMERIC, "C"), "Failed to set LC_NUMERIC for mpv", 1); + RETURN_UNLESS(setlocale(LC_NUMERIC, ""), "Failed to set LC_NUMERIC for mpv", 1); + RETURN_UNLESS(STR_MATCH(nl_langinfo(CODESET), "UTF-8"), "Your locale is not set to an UTF-8 one. " "Consider using en_US.UTF-8 or fr_FR.UTF-8!", 1); int autoclear; int opt;