summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2009-10-02 14:58:10 +0000
committerCorinna Vinschen <corinna@vinschen.de>2009-10-02 14:58:10 +0000
commit0ca6c6b802e02d584e3f0ac4bfa2b5bf3676a897 (patch)
treee19896efd3e5372d153d27f392d736979594e3a4
parent0e03c708bedb2654cdf9fff96fb29ce0fdae62dc (diff)
downloadcygnal-0ca6c6b802e02d584e3f0ac4bfa2b5bf3676a897.tar.gz
cygnal-0ca6c6b802e02d584e3f0ac4bfa2b5bf3676a897.tar.bz2
cygnal-0ca6c6b802e02d584e3f0ac4bfa2b5bf3676a897.zip
* dcrt0.cc (dll_crt0_1): Drop calls to setlocale/_setlocale_r. Just
call initial_setlocale from here. * syscalls.cc (initial_setlocale): Set internal charset and revert application locale to "C". (setlocale): Don't set Cygwin's internal charset here.
-rw-r--r--winsup/cygwin/ChangeLog8
-rw-r--r--winsup/cygwin/dcrt0.cc6
-rw-r--r--winsup/cygwin/syscalls.cc28
3 files changed, 31 insertions, 11 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 0ecfb5f1a..0df3c7974 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,11 @@
+2009-10-02 Corinna Vinschen <corinna@vinschen.de>
+
+ * dcrt0.cc (dll_crt0_1): Drop calls to setlocale/_setlocale_r. Just
+ call initial_setlocale from here.
+ * syscalls.cc (initial_setlocale): Set internal charset and revert
+ application locale to "C".
+ (setlocale): Don't set Cygwin's internal charset here.
+
2009-10-02 Christopher Faylor <me+cygwin@cgf.cx>
* dcrt0.cc (dll_crt0_1): Move cxx_malloc reset kluge from here.
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 6e4129298..1816f2e7f 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -768,6 +768,8 @@ dll_crt0_0 ()
void
dll_crt0_1 (void *)
{
+ extern void initial_setlocale ();
+
if (dynamically_loaded)
sigproc_init ();
check_sanity_and_sync (user_data);
@@ -940,9 +942,7 @@ dll_crt0_1 (void *)
LoadLibrary serialization. */
ld_preload ();
/* Set internal locale to the environment settings. */
- setlocale (LC_CTYPE, "");
- /* Reset application locale to "C" per POSIX */
- _setlocale_r (_REENT, LC_CTYPE, "C");
+ initial_setlocale ();
if (user_data->main)
cygwin_exit (user_data->main (__argc, __argv, *user_data->envptr));
__asm__ (" \n\
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 1d160d369..cd8909d89 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -4209,6 +4209,24 @@ internal_setlocale ()
setenv ("PATH", c_path, 1);
}
+/* Called from dll_crt0_1, before calling the application's main().
+ Set the internal charset according to the environment locale settings.
+ Check if a required codepage is available, and only switch internal
+ charset if so. Afterwards, reset application locale to "C" per POSIX. */
+void
+initial_setlocale ()
+{
+ char *ret = _setlocale_r (_REENT, LC_CTYPE, "");
+ if (ret && check_codepage (ret)
+ && strcmp (cygheap->locale.charset, __locale_charset ()) != 0)
+ internal_setlocale ();
+ _setlocale_r (_REENT, LC_CTYPE, "C");
+}
+
+/* Like newlib's setlocale, but additionally check if the charset needs
+ OS support and the required codepage is actually installed. If codepage
+ is not available, revert to previous locale and return NULL. For details
+ about codepage availability, see the comment in check_codepage() above. */
extern "C" char *
setlocale (int category, const char *locale)
{
@@ -4216,13 +4234,7 @@ setlocale (int category, const char *locale)
if (locale && !wincap.has_always_all_codepages ())
stpcpy (old, _setlocale_r (_REENT, category, NULL));
char *ret = _setlocale_r (_REENT, category, locale);
- if (ret && locale)
- {
- if (!(ret = check_codepage (ret)))
- _setlocale_r (_REENT, category, old);
- else if (!*locale && strcmp (cygheap->locale.charset,
- __locale_charset ()) != 0)
- internal_setlocale ();
- }
+ if (ret && locale && !(ret = check_codepage (ret)))
+ _setlocale_r (_REENT, category, old);
return ret;
}