List Info

Thread: win32 - file test operators don't work for //?/UNC/server/file filenames




win32 - file test operators don't work for //?/UNC/server/file filenames
user name
2007-09-10 11:41:21
# New Ticket Created by  "Davies, Alex" 
# Please include the string:  [perl #45331]
# in the subject line of all future correspondence about
this issue. 
# <URL: h
ttp://rt.perl.org/rt3/Ticket/Display.html?id=45331 >


This is a bug report for perl from adaviesptc.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:

\?UNCserverfolderfilename

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
"\?UNCserverfile"
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;
	}




[Please do not change anything below this line]
------------------------------------------------------------
-----
---
Flags:
    category=core
    severity=low
---
Site configuration information for perl v5.8.7:

Configured by adavies at Thu Aug 11 14:02:10 2005.

Summary of my perl5 (revision 5 version 8 subversion 7)
configuration:
  Platform:
    osname=MSWin32, osvers=5.1,
archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=define use5005threads=undef
useithreads=define
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define
usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags ='-nologo -Gf -W3 -MD -DNDEBUG -O1
-DWIN32
-D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT 
-DPERL_IMPLICIT_CONTEXT
-DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
    optimize='-MD -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='12.00.8804', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8,
byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define,
longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8,
Off_t='__int64',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -release
-libpath:"c:perl3libCORE"  -machine86'
    libpth=lib
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib 
version.lib
odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib
gdi32.lib
winspool.lib  comdlg32.lib advapi32.lib shell32.lib
ole32.lib
oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib
winmm.lib
version.lib odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes,
libperl=perl58.lib
    gnulibc_version='undef'
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef,
ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib
-release
-libpath:"c:perl3libCORE"  -machine86'

Locally applied patches:
    

---
INC
for perl v5.8.7:
    C:/perl3/lib
    C:/perl3/site/lib
    .

---
Environment for perl v5.8.7:
    HOME=C:alex
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
 
PATH=C:WINNTsystem32;C:WINNT;C:WINNTSystem32Wbem;C:pe
rl3bin;D:a
lexbin;C:cygwinbin;C:Program FilesPerforce;C:Program
FilesMicrosoft Visual StudioVC98Bin;C:Program
FilesMicrosoft Visual
StudioCommonMSDev98Bin;C:Program FilesMicrosoft Visual
StudioVC98MFCLib;
    PERL_BADLANG (unset)
    SHELL (unset)


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )