Skip to content

Commit 7e5415e

Browse files
committed
Use C.UTF-8 instead of C if available
Mostly everything around us is UTF-8 these days, we need to get on with the times. Especially now that glibc >= 2.35 finally supports it too. Attempt to detect C.UTF-8 availability in cmake and prefer when available, fall back to C when not. Fixes: #2587
1 parent f9775b4 commit 7e5415e

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ function(makemacros)
130130
findutil(__CPP cpp)
131131
findutil(__CXX c++)
132132

133+
# Try to determine if C.UTF-8 is available
134+
execute_process(COMMAND locale -a
135+
OUTPUT_STRIP_TRAILING_WHITESPACE
136+
OUTPUT_VARIABLE locale_a)
137+
separate_arguments(locales UNIX_COMMAND ${locale_a})
138+
list(FIND locales C.utf8 have_c_utf8)
139+
if (have_c_utf8 GREATER_EQUAL 1)
140+
set(C_LOCALE "C.UTF-8")
141+
else()
142+
set(C_LOCALE "C")
143+
endif()
144+
message(DEBUG " C locale ${C_LOCALE}")
145+
133146
list(GET db_backends 0 DB_BACKEND)
134147

135148
set(host_cpu ${CMAKE_HOST_SYSTEM_PROCESSOR})

build/files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2415,7 +2415,7 @@ static void processSpecialDir(rpmSpec spec, Package pkg, FileList fl,
24152415
appendStringBuf(docScript, sdenv);
24162416
appendStringBuf(docScript, "=$RPM_BUILD_ROOT");
24172417
appendLineStringBuf(docScript, sd->dirname);
2418-
appendLineStringBuf(docScript, "export LC_ALL=C");
2418+
appendLineStringBuf(docScript, "export LC_ALL=" C_LOCALE);
24192419
appendStringBuf(docScript, "export ");
24202420
appendLineStringBuf(docScript, sdenv);
24212421
appendLineStringBuf(docScript, mkdocdir);

config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114

115115
#define UID_0_USER "@UID_0_USER@"
116116
#define GID_0_GROUP "@GID_0_GROUP@"
117+
#define C_LOCALE "@C_LOCALE@"
117118

118119
#define PACKAGE "@PROJECT_NAME@"
119120
#define VERSION "@PROJECT_VERSION@"

macros.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ Supplements: (%{name} = %{version}-%{release} and langpacks-%{1})\
772772
RPM_PACKAGE_VERSION=\"%{VERSION}\"\
773773
RPM_PACKAGE_RELEASE=\"%{RELEASE}\"\
774774
export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE\
775-
LANG=C\
775+
LANG=@C_LOCALE@\
776776
export LANG\
777777
unset CDPATH DISPLAY ||:\
778778
unset DEBUGINFOD_URLS ||:\

rpmio/rpmglob.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ int rpmGlobPath(const char * pattern, rpmglobFlags flags,
9696
t = setlocale(LC_CTYPE, NULL);
9797
if (t)
9898
old_ctype = xstrdup(t);
99-
(void) setlocale(LC_COLLATE, "C");
100-
(void) setlocale(LC_CTYPE, "C");
99+
(void) setlocale(LC_COLLATE, C_LOCALE);
100+
(void) setlocale(LC_CTYPE, C_LOCALE);
101101
#endif
102102

103103
gl.gl_pathc = 0;

0 commit comments

Comments
 (0)