aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/locale
diff options
context:
space:
mode:
authorYuri Pankov <yuripv@FreeBSD.org>2023-03-28 15:10:47 +0000
committerYuri Pankov <yuripv@FreeBSD.org>2023-09-20 13:10:52 +0000
commita4916232acd614d4d7d7226d678b427aacb9730e (patch)
treefd2ed6248966a8cd74c1624c7160f79d7599e8db /lib/libc/locale
parent8303afca1765148d0069ce5144072b3ae9cab61e (diff)
libc: use separate collate objects for C, POSIX, and C.UTF-8
Fix newlocale() overwriting the locale name in collate object when same instance was used for those locales, and querylocale() reporting unexpected value for LC_COLLATE_MASK. PR: 255646, 269375 Reviewed by: markj, bapt (previous version) Differential Revision: https://reviews.freebsd.org/D30146 (cherry picked from commit 269dea90d6eb32690730b0f6a17fb41170483104)
Diffstat (limited to 'lib/libc/locale')
-rw-r--r--lib/libc/locale/collate.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c
index 3031d33dbb08..be995a5b963f 100644
--- a/lib/libc/locale/collate.c
+++ b/lib/libc/locale/collate.c
@@ -66,6 +66,14 @@ struct xlocale_collate __xlocale_C_collate = {
{{0}, "C"}, 1, 0, 0, 0
};
+struct xlocale_collate __xlocale_POSIX_collate = {
+ {{0}, "POSIX"}, 1, 0, 0, 0
+};
+
+struct xlocale_collate __xlocale_CUTF8_collate = {
+ {{0}, "C.UTF-8"}, 1, 0, 0, 0
+};
+
static int
__collate_load_tables_l(const char *encoding, struct xlocale_collate *table);
@@ -82,10 +90,13 @@ destruct_collate(void *t)
void *
__collate_load(const char *encoding, __unused locale_t unused)
{
- if (strcmp(encoding, "C") == 0 || strcmp(encoding, "POSIX") == 0 ||
- strncmp(encoding, "C.", 2) == 0) {
+ if (strcmp(encoding, "C") == 0)
return (&__xlocale_C_collate);
- }
+ else if (strcmp(encoding, "POSIX") == 0)
+ return (&__xlocale_POSIX_collate);
+ else if (strcmp(encoding, "C.UTF-8") == 0)
+ return (&__xlocale_CUTF8_collate);
+
struct xlocale_collate *table = calloc(sizeof(struct xlocale_collate),
1);
if (table == NULL)