Opened 4 months ago

#18980 new bug

setlocale does not accept a string returned by setlocale as argument

Reported by: bhaible Owned by: nobody
Priority: normal Milestone: Unscheduled
Component: System/POSIX Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

POSIX specifies that "The string returned by setlocale() is such that a subsequent call with that string and its associated category shall restore that part of the global locale."

This is meant to hold also for LC_ALL, and is the primary means of being able to switch to a different locale and then come back to the previous locale. Also, this rule is the basis of POSIX getlocalename_l.

This rule holds on all operating systems, except Haiku.

How to reproduce: Compile the attached program.

gcc -Wall foo.c

Run it.

./a.out en_US.UTF-8 de_DE.UTF-8 es_ES.UTF-8

Expected output:

LC_CTYPE    -> en_US.UTF-8
LC_NUMERIC  -> de_DE.UTF-8
LC_COLLATE  -> es_ES.UTF-8
LC_ALL -> LC_COLLATE=es_ES.UTF-8;LC_CTYPE=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_NUMERIC=de_DE.UTF-8;LC_TIME=en_US.UTF-8
After calling setlocale with this value:
LC_CTYPE    -> en_US.UTF-8
LC_NUMERIC  -> de_DE.UTF-8
LC_COLLATE  -> es_ES.UTF-8
Successful.

Actual output:

LC_CTYPE    -> en_US.UTF-8
LC_NUMERIC  -> de_DE.UTF-8
LC_COLLATE  -> es_ES.UTF-8
LC_ALL -> LC_COLLATE=es_ES.UTF-8;LC_CTYPE=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_NUMERIC=de_DE.UTF-8;LC_TIME=en_US.UTF-8
Switching to the mixed locale failed!

Seen in Haiku hrev57823 (from 2024-07-15).

Attachments (1)

foo.c (4.9 KB ) - added by bhaible 4 months ago.
test case foo.c

Download all attachments as: .zip

Change History (1)

by bhaible, 4 months ago

Attachment: foo.c added

test case foo.c

Note: See TracTickets for help on using tickets.