[PATCH/RFA]: Allow default locale different from "C"
Jeff Johnston
jjohnstn@redhat.com
Thu Oct 8 16:44:00 GMT 2009
On 07/10/09 01:07 PM, Corinna Vinschen wrote:
> Hi,
>
> per POSIX, a system can have a default locale different from "C".
> See http://www.opengroup.org/onlinepubs/7990989775/xbd/locale.html:
>
> "All implementations define a locale as the default locale, to be
> invoked when no environment variables are set, or set to the empty
> string. This default locale can be the POSIX locale or any other,
> implementation-dependent locale."
>
> To allow this, the below patch adds a global variable which can be set
> to some other value than the default value in a system-dependent manner.
> On Cygwin we're planning to allow to set a default locale via a file,
> like, for instance, /etc/default/locale, or /etc/sysconfig/locale.
>
> Since we're heading straight to UTF-8 as default charset, this patch
> also introduces a define DEFAULT_LOCALE, which is set to "C.UTF-8"
> on Cygwin, to "C" otherwise.
>
> Ok to apply?
>
I'm striving to remove all the OS/platform checks throughout shared code
so I would prefer you do it this way:
#ifndef DEFAULT_LOCALE
#define DEFAULT_LOCALE "C"
#endif
and then set DEFAULT_LOCALE in libc/include/sys/config.h or
configure.host for Cygwin.
That way, any platform may reset it if desired and we don't have a huge
if/else check in the code.
Ok to apply if you do it that way.
-- Jeff J.
>
> Thanks,
> Corinna
>
>
> * libc/locale/locale.c (DEFAULT_LOCALE): New define.
> (__default_locale): New global variable set to the default
> locale.
> (__get_locale_env): Return __default_locale rather than fixed
> string "C".
>
>
> Index: libc/locale/locale.c
> ===================================================================
> RCS file: /cvs/src/src/newlib/libc/locale/locale.c,v
> retrieving revision 1.28
> diff -u -p -r1.28 locale.c
> --- libc/locale/locale.c 29 Sep 2009 19:12:28 -0000 1.28
> +++ libc/locale/locale.c 7 Oct 2009 17:06:11 -0000
> @@ -205,6 +205,20 @@ static char *categories[_LC_LAST] = {
> };
>
> /*
> + * Default locale per POSIX.
> + */
> +#ifdef __CYGWIN__
> +#define DEFAULT_LOCALE "C.UTF-8"
> +#else
> +#define DEFAULT_LOCALE "C"
> +#endif
> +/*
> + * This variable can be changed by any outside mechanism. This allows,
> + * for instance, to load the default locale from a file.
> + */
> +char __default_locale[ENCODING_LEN + 1] = DEFAULT_LOCALE;
> +
> +/*
> * Current locales for each category
> */
> static char current_categories[_LC_LAST][ENCODING_LEN + 1] = {
> @@ -731,9 +745,9 @@ __get_locale_env(struct _reent *p, int c
> if (env == NULL || !*env)
> env = _getenv_r (p, "LANG");
>
> - /* 4. if none is set, fall to "C" */
> + /* 4. if none is set, fall to default locale */
> if (env == NULL || !*env)
> - env = "C";
> + env = __default_locale;
>
> return env;
> }
>
>
More information about the Newlib
mailing list