develooper Front page | perl.perl5.porters | Postings from August 2012

[perl #45331] win32 - file test operators don't work for //?/UNC/server/file filenames

Thread Next
From:
James E Keenan via RT
Date:
August 13, 2012 16:10
Subject:
[perl #45331] win32 - file test operators don't work for //?/UNC/server/file filenames
Message ID:
rt-3.6.HEAD-11172-1344899426-746.45331-15-0@perl.org
On Mon Sep 10 09:41:21 2007, adavies@ptc.com wrote:
> This is a bug report for perl from adavies@ptc.com,
> generated with the help of perlbug 1.35 running under perl v5.8.7.
> 
> 
> -----------------------------------------------------------------
> [Please enter your report here]
> 
> On win32 you can use UNC pathanmes of the form:
> 
> \\?\UNC\server\folder\filename
> 
> Perl can C<open> these files ok, but C<-f>, C<-e> etc. 
> incorrectly return false for these filenames.
> However, they do work for directory names in this format.
> 
> The code in question is in win32/win32.c's win32_stat():
> 
> # %<
> 
>  #if defined(WIN64) || defined(USE_LARGE_FILES)
>     res = _stati64(path, sbuf);
>  #else
>     res = stat(path, sbuf);
>  #endif
>     sbuf->st_nlink = nlink;
> 
>  if (res < 0) {
>     /* CRT is buggy on sharenames, so make sure it really isn't.
>      * XXX using GetFileAttributesEx() will enable us to set
>      * sbuf->st_*time (but note that's not available on the
>      * Windows of 1995) */
>     DWORD r = GetFileAttributesA(path);
>     if (r != 0xffffffff && (r & FILE_ATTRIBUTE_DIRECTORY)) {
>         /* sbuf may still contain old garbage since stat() failed */
>         Zero(sbuf, 1, Stat_t);
>         sbuf->st_mode = S_IFDIR | S_IREAD;
>         errno = 0;
>         if (!(r & FILE_ATTRIBUTE_READONLY))
>             sbuf->st_mode |= S_IWRITE | S_IEXEC;
>         return 0;
>     }
> 
> # >%
> 
> 
> Note that GetFileAttributesA() does succeed for "\\?\UNC\server\file"
> format filesnames... but the result does not have the
> "FILE_ATTRIBUTE_DIRECTORY" bit set.
> 
> Is there any reason why this isn't coded as (untested):
> 
> 
> 	DWORD r = GetFileAttributesA(path);
> 	if (r != 0xffffffff) {
> 	    /* sbuf may still contain old garbage since stat() failed */
> 	    Zero(sbuf, 1, Stat_t);
> 	    sbuf->st_mode = S_IREAD;
> 	    if (r & FILE_ATTRIBUTE_DIRECTORY)
> 		sbuf->st_mode |= S_IFDIR;
> 	    errno = 0;
> 	    if (!(r & FILE_ATTRIBUTE_READONLY))
> 		sbuf->st_mode |= S_IWRITE | S_IEXEC;
> 	    return 0;
> 	}
> 
> 
> 
> 

Can anyone on Win32 confirm whether these problems persist in a
supported version of Perl (5.14 or 5.16)?

Thank you very much.
Jim Keenan

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=45331

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About