From 8404ae034f3544f3f4a6f2cad9d90c6da9d2ea4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 19 Jan 2024 21:06:42 +0800 Subject: [PATCH] Locale: improve detection Linux: always use `setlocale`, fix #688 Windows: don't append `UTF-8` --- src/detection/locale/locale_linux.c | 56 +++------------------------ src/detection/locale/locale_windows.c | 5 --- 2 files changed, 5 insertions(+), 56 deletions(-) diff --git a/src/detection/locale/locale_linux.c b/src/detection/locale/locale_linux.c index 99edccec0..2b0ad2d4f 100644 --- a/src/detection/locale/locale_linux.c +++ b/src/detection/locale/locale_linux.c @@ -1,61 +1,15 @@ #include "detection/locale/locale.h" -#include "common/properties.h" -#include "common/parsing.h" -#include #include -FF_MAYBE_UNUSED -static void getLocaleFromEnv(FFstrbuf* locale) -{ - ffStrbufAppendS(locale, getenv("LANG")); - if(locale->length > 0) - return; - - ffStrbufAppendS(locale, getenv("LC_ALL")); - if(locale->length > 0) - return; - - ffStrbufAppendS(locale, getenv("LC_MESSAGES")); -} - -static void getLocaleFromStdFn(FFstrbuf* locale) -{ - #ifdef LC_MESSAGES - ffStrbufAppendS(locale, setlocale(LC_MESSAGES, NULL)); - - if(locale->length > 0) - return; - #endif - - ffStrbufAppendS(locale, setlocale(LC_ALL, NULL)); -} - void ffDetectLocale(FFstrbuf* result) { - #if !(defined(__APPLE__) || defined(_WIN32)) - - //Ubuntu (and deriviates) use a non standard locale file. - //Parse it first, because on distributions where it exists, it takes precedence. - //Otherwise use the standard etc/locale.conf file. - ffParsePropFile(FASTFETCH_TARGET_DIR_ETC"/default/locale", "LANG =", result); - - if(result->length > 0) - return; - - ffParsePropFile(FASTFETCH_TARGET_DIR_ETC"/locale.conf", "LANG =", result); - if(result->length > 0) - return; + #ifdef LC_MESSAGES + ffStrbufAppendS(result, setlocale(LC_MESSAGES, NULL)); + if(result->length > 0) + return; #endif - #ifndef _WIN32 - - getLocaleFromEnv(result); - if(result->length > 0) - return; - - #endif - - getLocaleFromStdFn(result); + ffStrbufAppendS(result, setlocale(LC_ALL, NULL)); } diff --git a/src/detection/locale/locale_windows.c b/src/detection/locale/locale_windows.c index 128913129..c14732ffb 100644 --- a/src/detection/locale/locale_windows.c +++ b/src/detection/locale/locale_windows.c @@ -9,10 +9,5 @@ void ffDetectLocale(FFstrbuf* result) wchar_t name[LOCALE_NAME_MAX_LENGTH]; int size = GetUserDefaultLocaleName(name, LOCALE_NAME_MAX_LENGTH); if (size > 1) // including '\0' - { ffStrbufSetNWS(result, (uint32_t)size - 1, name); - ffStrbufAppendS(result, ".UTF-8"); // set explicitly in `ffInitInstance` - } - else - ffStrbufSetS(result, setlocale(LC_ALL, NULL)); }