This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH/RFA]: Allow default locale different from "C"


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?


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;
 }


-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]