bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Using ENVIRON["LANG"] = "C" instead of --characters-as-by


From: Eli Zaretskii
Subject: Re: [bug-gawk] Using ENVIRON["LANG"] = "C" instead of --characters-as-bytes
Date: Thu, 12 Mar 2015 22:32:27 +0200

> Date: Thu, 12 Mar 2015 20:21:52 +0100
> From: Hermann Peifer <address@hidden>
> CC: address@hidden
> 
> Thanks. I am using gawk/master where the NEWS say:
> 
> 1. If not in POSIX mode, changes to ENVIRON are reflected into
>     gawk's environment, affecting any programs run by system()
>     or for piped redirections. This can also affect built-in routines, such
>     as mktime(), which is typically influenced by the TZ environment variable.

Where does this say that setting LC_* triggers a call to 'setlocale'?

'mktime' is affected because it looks at TZ each time it is called.
By contrast, locale-dependent functions, like 'strcasecmp' and
'strcoll', don't look at LC_*, and instead rely on 'setlocale' to set
up tables for them.  So a call to 'setlocale' _is_ needed after
setting LC_* variables.  And AFAICS, there's no such call in gawk on
master.

> # This works as expected (my locale is en_US.UTF-8)
> $ LC_ALL=C awk -f myscript.awk ...

Because at program startup the runtime automatically calls 'setlocale'
(or does its equivalent) -- this is a basic requirement of standard
C.  So when Gawk starts it calls 'setlocale', which notices the
setting and does what you want.

By contrast, in your example the variable is set after Gawk already
started, so nothing guarantees 'setlocale' will be called.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]