From b6c6ea43f30ee958ca1f0af950af01f683f7b5c9 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 13 May 2009 15:00:06 +0000 Subject: * cygheap.h (cwdstuff): Convert to class. Make posix and dir private. (cwdstuff::get_posix): New method. (cwdstuff::reset_posix): New method. * dcrt0.cc (dll_crt0_1): Call setlocale rather than _setlocale_r. * environ.cc (environ_init): Ditto. Prefer "C" locale over current codepage default locale. * path.cc (chdir): Use cwdstuff::get_posix method instead of accessing cwdstuff::posix directly. (cwdstuff::set): Defer creating posix path to first usage. (cwdstuff::get_posix): Create posix path if it's empty, and return it. (cwdstuff::get): Create posix path if it's empty. * strfuncs.cc (sys_cp_wcstombs): Use UTF-8 conversion in the "C" locale. (sys_cp_mbstowcs): Ditto. * syscalls.cc (gen_full_path_at): Fetch CWD posix path locked. (setlocale): Implement here. Reset CWD posix path. --- winsup/cygwin/path.cc | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'winsup/cygwin/path.cc') diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index ec5c40b5c..ca2df5872 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -2599,7 +2599,7 @@ chdir (const char *in_dir) /* Note that we're accessing cwd.posix without a lock here. I didn't think it was worth locking just for strace. */ syscall_printf ("%d = chdir() cygheap->cwd.posix '%s' native '%S'", res, - cygheap->cwd.posix, path.get_nt_native_path ()); + cygheap->cwd.get_posix (), path.get_nt_native_path ()); MALLOC_CHECK; return res; } @@ -3230,8 +3230,8 @@ cwdstuff::set (PUNICODE_STRING nat_cwd, const char *posix_cwd, bool doit) posix_cwd = (const char *) tp.c_get (); mount_table->conv_to_posix_path (win32.Buffer, (char *) posix_cwd, 0); } - posix = (char *) crealloc_abort (posix, strlen (posix_cwd) + 1); - stpcpy (posix, posix_cwd); + if (posix) + posix[0] = '\0'; } out: @@ -3240,6 +3240,21 @@ out: } /* Copy the value for either the posix or the win32 cwd into a buffer. */ +char * +cwdstuff::get_posix () +{ + if (!posix || !*posix) + { + tmp_pathbuf tp; + + char *tocopy = tp.c_get (); + mount_table->conv_to_posix_path (win32.Buffer, tocopy, 0); + posix = (char *) crealloc_abort (posix, strlen (tocopy) + 1); + stpcpy (posix, tocopy); + } + return posix; +} + char * cwdstuff::get (char *buf, int need_posix, int with_chroot, unsigned ulen) { @@ -3265,6 +3280,13 @@ cwdstuff::get (char *buf, int need_posix, int with_chroot, unsigned ulen) sys_wcstombs (tocopy, NT_MAX_PATH, win32.Buffer, win32.Length / sizeof (WCHAR)); } + else if (!posix || !*posix) + { + tocopy = tp.c_get (); + mount_table->conv_to_posix_path (win32.Buffer, tocopy, 0); + posix = (char *) crealloc_abort (posix, strlen (tocopy) + 1); + stpcpy (posix, tocopy); + } else tocopy = posix; -- cgit v1.2.3