diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2010-08-19 14:14:31 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2010-08-19 14:14:31 +0400 |
commit | e652eb9230f1182a18b514317ec6cf22a168ca3f (patch) | |
tree | d082931adb055b7f5a93e5f23d84b0e31ce186b4 /winsup/cygwin/external.cc | |
parent | 1087b2462f99ee7a1e06259e88559d2e5d22b1d9 (diff) |
* external.cc (sync_wincwd): New function.
(cygwin_internal): Rename CW_SETCWD to CW_SYNC_WINCWD. Call
sync_wincwd from here.
* include/sys/cygwin.h (cygwin_getinfo_types): Rename CW_SETCWD to
CW_SYNC_WINCWD.
Diffstat (limited to 'winsup/cygwin/external.cc')
-rw-r--r-- | winsup/cygwin/external.cc | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/winsup/cygwin/external.cc b/winsup/cygwin/external.cc index 53ce5b1b8..e8d3580f4 100644 --- a/winsup/cygwin/external.cc +++ b/winsup/cygwin/external.cc @@ -162,6 +162,29 @@ sync_winenv () free (envblock); } +/* Synchronize Win32 CWD with Cygwin CWD. Return -1 and set errno if + setting the Win32 CWD fails. */ +static unsigned long +sync_wincwd () +{ + unsigned long ret = (unsigned long) -1; + /* Lock cwd. We're accessing it directly here. */ + cygheap->cwd.cwd_lock.acquire (); + /* First check if the path can work at all. Fortunately we already have + an error code in the cwd, which was stored there for the sake of + spawn_guts. */ + if (cygheap->cwd.get_error ()) + set_errno (cygheap->cwd.get_error ()); + /* Of course, SetCurrentDirectoryW still can fail, for instance, if the + CWD has been removed or renamed in the meantime. */ + else if (!SetCurrentDirectoryW (cygheap->cwd.win32.Buffer)) + __seterrno (); + else + ret = 0; + cygheap->cwd.cwd_lock.release (); + return ret; +} + /* * Cygwin-specific wrapper for win32 ExitProcess and TerminateProcess. * It ensures that the correct exit code, derived from the specified @@ -514,13 +537,10 @@ cygwin_internal (cygwin_getinfo_types t, ...) res = (uintptr_t) strerror (err); } break; + case CW_SYNC_WINCWD: + res = sync_wincwd (); + break; - case CW_SETCWD: - { - cygheap->cwd.cwd_lock.acquire (); - PWCHAR cwd = cygheap->cwd.win32.Buffer; - res = !SetCurrentDirectoryW (cwd); - } default: set_errno (ENOSYS); } |