[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: macOS 12 - cannot override LC_ALL=C setting from environment
From: |
Bruno Haible |
Subject: |
Re: macOS 12 - cannot override LC_ALL=C setting from environment |
Date: |
Sun, 01 Dec 2024 02:41:43 +0100 |
Hi Gavin and Patrice,
> I got it down to a short C program:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <libintl.h>
>
> int
> main (void)
> {
> char *a = setlocale(LC_ALL, "en_US.UTF-8");
> printf("setlocale returned %s\n", a);
> setenv("LANG", "pt", 1);
> bindtextdomain("texinfo_document", "../../../build/tp/LocaleData");
> textdomain("texinfo_document");
> char *s = gettext("Special Form");
> printf("result %s\n", s);
> }
> ...
> However, running "LC_ALL=C ./a.out" does not:
>
> setlocale returned en_US.UTF-8
> result Special Form
>
> So even though we try to override LC_ALL by calling setlocale in the
> program, nothing happens.
The reason why it does not work is that this program is not following
the documented requirement from
https://www.gnu.org/software/gettext/manual/html_node/C.html :
"Programmer must call setlocale (LC_ALL, "")"
In other words, instead of doing
setlocale (LC_ALL, "en_US.UTF-8");
you need to do
setenv ("LC_ALL", "en_US.UTF-8", 1);
setlocale (LC_ALL, "");
It's unfortunate that your code is working as expected on GNU, FreeBSD, NetBSD,
Solaris systems but not on macOS, Windows, AIX, and OpenBSD. But there are
(complicated) reasons for it, see
https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/localename-unsafe.c;h=0a2654d8a3fcd025c80d4ad6eb34ce02c13879e5;hb=HEAD#l3202
Bruno