On Wed, Jun 24, 2026 at 11:02 PM Collin Funk <[email protected]> wrote:
>
> Grisha Levit <[email protected]> writes:
>
> > I think this behavior might just be a gnulib bug?
> >
> > AFAICT, what happens in this case (no relevant variables in the
> > environment, System Preferences Language/Region set such that they do
> > not match a valid locale):
> >
> > libintl_setlocale(LC_ALL,"") will set the LC_NUMERIC category (and others) 
> > by:
> > * checking the value of the "AppleLocale" preference value (en_DE)
> > * calling the system setlocale with this value (which fails)
> > * finding an appropriate locale name based on the territory (de_DE)
> > * calling the system setlocale with this value
> >
> > libintil_setlocale(LC_NUMERIC, "") uses a different code path, which
> > does not do the last two steps, and so will just fail.
>
> Does bash use Gnulib's setlocale on MacOS? It doesn't have the
> setlocale.m4 file which would be used by Gnulib:
>
>     $ find . -name 'setlocale.m4' | wc -l
>     0
>
> And nothing ever sets REPLACE_SETLOCALE to 1:
>
>     $ git grep -F 'REPLACE_SETLOCALE'
>     configure:REPLACE_SETLOCALE
>     configure:  REPLACE_SETLOCALE=0;
>     m4/locale_h.m4:  REPLACE_SETLOCALE=0;    AC_SUBST([REPLACE_SETLOCALE])
>
> It looks like the version in lib/intl/setlocale.c is a old 2019 version
> from Gnulib that is for systems without the function.

AFAICT the setlocale from libintl gets used on macos whenever bash is
built without --disable-nls.
The homebrew build links with libintl from the gettext formula, and
exhibits the same behavior.

Looking at setlocale from gnulib, I see that when LC_ALL is being set,
there are calls to get_main_locale_with_same_territory [1] /
get_main_locale_with_same_language [2]. But there is no such logic for
other categories [3], which I think explains the difference in
behavior.

[1] 
https://github.com/coreutils/gnulib/blob/e191cc8118cbb5eee3710167edc8e822cdbf4214/lib/setlocale.c#L1589
[2] 
https://github.com/coreutils/gnulib/blob/e191cc8118cbb5eee3710167edc8e822cdbf4214/lib/setlocale.c#L1565
[3] 
https://github.com/coreutils/gnulib/blob/e191cc8118cbb5eee3710167edc8e822cdbf4214/lib/setlocale.c#L1624

Reply via email to