This is the mail archive of the
cygwin-talk
mailing list for the cygwin project.
Re: Cygwin mentioned in "current directory" discussion
- From: Corinna Vinschen <corinna-cygwin at cygwin dot com>
- To: cygwin-talk at cygwin dot com
- Date: Mon, 15 Nov 2010 20:26:09 +0100
- Subject: Re: Cygwin mentioned in "current directory" discussion
- References: <20101110043738.GA19327@ednor.casa.cgf.cx>
- Reply-to: cygwin-talk at cygwin dot com
- Reply-to: The Vulgar and Unprofessional Cygwin-Talk List <cygwin-talk at cygwin dot com>
On Nov 9 23:37, Christopher Faylor wrote:
> https://blogs.msdn.com/b/oldnewthing/archive/2010/11/09/10087919.aspx
This morning I added a comment to the blog, #42 in the list:
--- SNIP ---
[I wouldn't put it past the Cygwin guys to patch ntdll...-Joshua]
That's a bit over the top, but the new, undocumented way Vista and later
uses to set the CWD requires some serious hacking to get the Linux semantics
right.
Note that the problem is not that SetCurrentDirectory creates a
directory handle. The problem is that it creates a directory handle
without the chance to set certain flags, analogous to the CreateFile
call:
- SetCurrentDirectory always opens dirs without the FILE_SHARE_DELETE flag.
- SetCurrentDirectory always opens dirs without the FILE_FLAG_POSIX_SEMANTICS flag.
- SetCurrentDirectory always opens dirs without the FILE_FLAG_BACKUP_SEMANTICS flag.
Apart from that, an annoying problem of the SetCurrentDirectory call is
it's quite obvious flaw to allow only paths of up to 258 chars, even the
UNICODE variant. That's due to the fact that the CWD path storage is a
fixed buffer of 260 wide chars (including a trailing backslash and a
L'\0'). This is still true for the Vista/W7 style of CWD storage on the
heap, even though the method would easily allow longer paths.
A transparent solution for Windows 8 and later would be an Ex call as
proposed by Andy, like this:
BOOL SetCurrentDirectoryEx (LPCTSTR lpDirectoryName,
DWORD dwShareMode,
DWORD dwOpenFlags)
with SetCurrentDirectoryExW allowing the same long pathname syntax for
paths up to 32K as the CreateFileW and similar calls.
Actually, for Cygwin it would already be sufficient (and even more
convenient), to export the global pointer pointing to the current CWD
datastructure on the heap. Or better, to export the function which
returns this pointer. This would allow to get rid of the awkward code
which extracts this global pointer by scanning the
RtlGetCurrentDirectory_U function.
I guess this should go without saying, but it would be nice if this new
CWD storage method would be officially documented...
--- SNAP ---
Two minutes ago, I found that my comment had been silently removed!
I'm not aware that my comment contained offensive, abusive, or
disrespectful language. I'm really wondering why Raymond decided
to remove my comment. This is quite disappointing.
Corinna