On Sun, Mar 09, 2008 at 10:28:06AM +0100, Corinna Vinschen wrote: >Hi Brian, > >Thanks for your patch. I have a few nits, sorry. > >On Mar 8 20:13, Brian Dessent wrote: >> Index: cygcheck.cc >> =================================================================== >> RCS file: /cvs/src/src/winsup/utils/cygcheck.cc,v >> retrieving revision 1.97 >> diff -u -p -r1.97 cygcheck.cc >> --- cygcheck.cc 13 Jan 2008 13:41:45 -0000 1.97 >> +++ cygcheck.cc 9 Mar 2008 03:52:07 -0000 >> @@ -807,6 +807,31 @@ ls (char *f) >> display_error ("ls: CloseHandle()"); >> } >> >> +/* If s is non-NULL, save the CWD in a static buffer and set the CWD >> + to the dirname part of s. If s is NULL, restore the CWD last >> + saved. */ >> +static >> +void save_cwd_helper (const char *s) >> +{ >> + static char cwdbuf[MAX_PATH + 1]; >> + char dirnamebuf[MAX_PATH + 1]; >> + >> + if (s) >> + { >> + GetCurrentDirectory (sizeof (cwdbuf), cwdbuf); >> + >> + /* Remove the filename part from s. */ >> + strncpy (dirnamebuf, s, MAX_PATH); >> + dirnamebuf[MAX_PATH] = '\0'; // just in case strlen(s) > MAX_PATH >> + char *lastsep = strrchr (dirnamebuf, '\\'); >> + if (lastsep) >> + lastsep[1] = '\0'; >> + SetCurrentDirectory (dirnamebuf); >> + } >> + else >> + SetCurrentDirectory (cwdbuf); >> +} > >Given that Cygwin changes to support long path names, I don't really >like to see new code still using MAX_PATH and Win32 Ansi functions >in the utils dir. I know that the Win32 cwd is always restricted to >259 chars. However, there *is* a way to recognize the current working >directory of the parent Cygwin application. > >Bash as well as tcsh, as well as zsh (and probbaly pdksh, too) create an >environment variable $PWD. Maybe Cygwin should create $PWD for native >apps if it's not already available through the parent shell.
I'd really rather not do that. I don't think Cygwin should be polluting the environment any more than it has to. Even if this worked, it is easily defeatable by setting a PWD environment variable before running cygwin, so you'd have to keep track of this value through multiple levels of process invocation. I know everyone hates it but a cygwin_internal interface could be used to get the current working directory for applications that need it. I would think that only mingw-like applications working in close conjunction with cygwin would care about this. cgf