Skip to content

Commit b324e4f

Browse files
committed
Global: only enable locale if necessary
Fix #995
1 parent 550eeb8 commit b324e4f

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/common/init.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#include <stdlib.h>
1010
#include <unistd.h>
11-
#include <locale.h>
1211
#ifdef _WIN32
1312
#include <windows.h>
13+
#include <locale.h>
1414
#include "util/windows/unicode.h"
1515
#else
1616
#include <signal.h>
@@ -51,9 +51,6 @@ void ffInitInstance(void)
5151
#ifdef WIN32
5252
//https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setlocale-wsetlocale?source=recommendations&view=msvc-170#utf-8-support
5353
setlocale(LC_ALL, ".UTF8");
54-
#else
55-
// used for mbsrtowcs in Module `separator`
56-
setlocale(LC_ALL, "");
5754
#endif
5855

5956
initState(&instance.state);

src/detection/locale/locale_linux.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ void ffDetectLocale(FFstrbuf* result)
1212
if(result->length > 0)
1313
return;
1414

15+
setlocale(LC_ALL, "");
1516
#ifdef LC_MESSAGES
1617
ffStrbufAppendS(result, setlocale(LC_MESSAGES, NULL));
1718

18-
if(result->length > 0)
19-
return;
19+
if(result->length == 0)
20+
ffStrbufAppendS(result, setlocale(LC_ALL, NULL));
2021
#endif
21-
22-
ffStrbufAppendS(result, setlocale(LC_ALL, NULL));
22+
setlocale(LC_ALL, "C");
2323
}

src/modules/separator/separator.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "util/mallocHelper.h"
66
#include "util/wcwidth.h"
77

8+
#include <locale.h>
9+
810
static inline uint32_t max(uint32_t a, uint32_t b)
911
{
1012
return a > b ? a : b;
@@ -31,6 +33,8 @@ static inline uint32_t getWcsWidth(const FFstrbuf* mbstr, wchar_t* wstr, mbstate
3133

3234
void ffPrintSeparator(FFSeparatorOptions* options)
3335
{
36+
setlocale(LC_ALL, "");
37+
3438
mbstate_t state = {};
3539
bool fqdn = instance.config.modules.title.fqdn;
3640
const FFPlatform* platform = &instance.state.platform;
@@ -86,6 +90,8 @@ void ffPrintSeparator(FFSeparatorOptions* options)
8690
}
8791
}
8892
putchar('\n');
93+
94+
setlocale(LC_ALL, "C");
8995
}
9096

9197
bool ffParseSeparatorCommandOptions(FFSeparatorOptions* options, const char* key, const char* value)

0 commit comments

Comments
 (0)