Global: only enable locale if necessary

Fix  #995
This commit is contained in:
Carter Li
2024-06-07 08:59:58 +08:00
parent 550eeb850c
commit b324e4f664
3 changed files with 11 additions and 8 deletions
+1 -4
View File
@@ -8,9 +8,9 @@
#include <stdlib.h>
#include <unistd.h>
#include <locale.h>
#ifdef _WIN32
#include <windows.h>
#include <locale.h>
#include "util/windows/unicode.h"
#else
#include <signal.h>
@@ -51,9 +51,6 @@ void ffInitInstance(void)
#ifdef WIN32
//https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setlocale-wsetlocale?source=recommendations&view=msvc-170#utf-8-support
setlocale(LC_ALL, ".UTF8");
#else
// used for mbsrtowcs in Module `separator`
setlocale(LC_ALL, "");
#endif
initState(&instance.state);
+4 -4
View File
@@ -12,12 +12,12 @@ void ffDetectLocale(FFstrbuf* result)
if(result->length > 0)
return;
setlocale(LC_ALL, "");
#ifdef LC_MESSAGES
ffStrbufAppendS(result, setlocale(LC_MESSAGES, NULL));
if(result->length > 0)
return;
if(result->length == 0)
ffStrbufAppendS(result, setlocale(LC_ALL, NULL));
#endif
ffStrbufAppendS(result, setlocale(LC_ALL, NULL));
setlocale(LC_ALL, "C");
}
+6
View File
@@ -5,6 +5,8 @@
#include "util/mallocHelper.h"
#include "util/wcwidth.h"
#include <locale.h>
static inline uint32_t max(uint32_t a, uint32_t b)
{
return a > b ? a : b;
@@ -31,6 +33,8 @@ static inline uint32_t getWcsWidth(const FFstrbuf* mbstr, wchar_t* wstr, mbstate
void ffPrintSeparator(FFSeparatorOptions* options)
{
setlocale(LC_ALL, "");
mbstate_t state = {};
bool fqdn = instance.config.modules.title.fqdn;
const FFPlatform* platform = &instance.state.platform;
@@ -86,6 +90,8 @@ void ffPrintSeparator(FFSeparatorOptions* options)
}
}
putchar('\n');
setlocale(LC_ALL, "C");
}
bool ffParseSeparatorCommandOptions(FFSeparatorOptions* options, const char* key, const char* value)