Looks like a bug to me.
Linux:
>uname -a
Linux enterprise 2.6.37.6-foken #2 SMP Sun Aug 14 02:20:59 CEST 2011 x
+86_64 AMD Athlon(tm) II Neo N36L Dual-Core Processor AuthenticAMD GNU
+/Linux
>perl -E '$file=q[""]; say (-e($file) ? "yes" : "no")'
no
>perl -V
Summary of my perl5 (revision 5 version 12 subversion 3) configuration
+:
Platform:
osname=linux, osvers=2.6.35.10, archname=x86_64-linux-thread-multi
uname='linux midas64 2.6.35.10 #2 smp thu jan 6 19:06:19 cst 2011
+x86_64 amd athlon(tm) ii x2 235e processor authenticamd gnulinux '
config_args='-de -Dprefix=/usr -Dvendorprefix=/usr -Dcccdlflags=-f
+PIC -Dinstallprefix=/usr -Dlibpth=/usr/local/lib64 /usr/lib64 /lib64
+-Doptimize=-O2 -fPIC -Dusethreads -Duseithreads -Dpager=/usr/bin/less
+ -isr -Dinc_version_list=5.12.2 5.12.1 5.12.0 5.10.1 5.10.0 5.8.8 5.8
+.7 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 -Darchname=x86_64-linux'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=und
+ef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing
+ -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_
+FILE_OFFSET_BITS=64',
optimize='-O2 -fPIC',
cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -f
+stack-protector -I/usr/local/include'
ccversion='', gccversion='4.5.2', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1
+6
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
+ lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -fstack-protector'
libpth=/usr/local/lib64 /usr/lib64 /lib64
libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=/lib64/libc-2.12.2.so, so=so, useshrplib=false, libperl=libpe
+rl.a
gnulibc_version='2.12.2'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -O2 -fPIC -fstack-protector
+'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP USE_64_
+BIT_ALL
USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
USE_PERLIO USE_PERL_ATOF USE_REENTRANT_API
Built under linux
Compiled at Jan 26 2011 12:39:46
%ENV:
PERL_UNICODE="SDL"
@INC:
/usr/lib64/perl5/site_perl/5.12.3/x86_64-linux-thread-multi
/usr/lib64/perl5/site_perl/5.12.3
/usr/lib64/perl5/vendor_perl/5.12.3/x86_64-linux-thread-multi
/usr/lib64/perl5/vendor_perl/5.12.3
/usr/lib64/perl5/5.12.3/x86_64-linux-thread-multi
/usr/lib64/perl5/5.12.3
/usr/lib64/perl5/site_perl
/usr/lib64/perl5/vendor_perl
.
Windows:
C:\Users\alex>perl -E "$file=chr(34).chr(34); say $file.' '.(-e($file)
+ ? 'yes' : 'no')"
"" yes
C:\Users\alex>ver
Microsoft Windows [Version 6.1.7601]
C:\Users\alex>dir
Volume in drive C is System
Volume Serial Number is B663-2E5B
Directory of C:\Users\alex
24.06.2012 19:12 <DIR> .
24.06.2012 19:12 <DIR> ..
25.05.2012 23:46 <DIR> .gegl-0.0
24.06.2012 19:21 <DIR> .gimp-2.6
24.06.2012 19:12 6.262 .recently-used.xbel
28.05.2012 14:19 <DIR> .thumbnails
06.05.2012 23:44 <DIR> Contacts
24.06.2012 19:12 <DIR> Desktop
24.06.2012 19:41 <DIR> Documents
01.07.2012 19:22 <DIR> Downloads
24.06.2012 19:32 <DIR> Favorites
06.05.2012 23:44 <DIR> Links
16.06.2012 12:54 <DIR> Music
25.05.2012 23:50 <DIR> Pictures
06.05.2012 23:44 <DIR> Saved Games
06.05.2012 23:44 <DIR> Searches
06.05.2012 23:44 <DIR> Videos
15.06.2012 21:05 <DIR> Virtual Machines
1 File(s) 6.262 bytes
17 Dir(s) 11.921.534.976 bytes free
C:\Users\alex>perl -V
Summary of my perl5 (revision 5 version 14 subversion 2) configuration
+:
Platform:
osname=MSWin32, osvers=4.0, archname=MSWin32-x64-multi-thread
uname='Win32 strawberryperl 5.14.2.1 #1 Tue Nov 22 22:40:59 2011 x
+64'
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=und
+ef
use64bitint=define, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags =' -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -DPERL
+_TEXTMODE_SCRIPTS -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_
+IMPLICIT_SYS -fno-strict-aliasing -mms-bitfields',
optimize='-s -O2',
cppflags='-DWIN32'
ccversion='', gccversion='4.4.7', gccosandvers=''
intsize=4, longsize=4, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1
+2
ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='lo
+ng long', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='g++', ldflags ='-s -L"C:\strawberry\perl\lib\CORE" -L"C:\straw
+berry\c\lib"'
libpth=C:\strawberry\c\lib C:\strawberry\c\x86_64-w64-mingw32\lib
libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32
+-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -l
+mpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdl
+g32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_3
+2 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
libc=, so=dll, useshrplib=true, libperl=libperl514.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-mdll -s -L"C:\strawberry\perl\lib\CORE
+" -L"C:\strawberry\c\lib"'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
PERL_MALLOC_WRAP PERL_PRESERVE_IVUV PL_OP_SLAB
+_ALLOC
USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
USE_PERLIO USE_PERL_ATOF USE_SITECUSTOMIZE
Built under MSWin32
Compiled at Nov 22 2011 22:53:05
%ENV:
PERL_JSON_BACKEND="JSON::XS"
PERL_YAML_BACKEND="YAML"
@INC:
C:/strawberry/perl/site/lib
C:/strawberry/perl/vendor/lib
C:/strawberry/perl/lib
.
C:\Users\alex>
Even shorter:
C:\Users\alex>perl -E "stat(chr(34).chr(34)) or die $!; say 'huh?'"
huh?
C:\Users\alex>
vs.
>perl -E 'stat(q[""]) or die $!; say "huh?"'
No such file or directory at -e line 1.
>
If stat is successful, what is in stat()s return value?
C:\Users\alex>perl -MData::Dumper -E "@a=stat(chr(34).chr(34)) or die
+$!; say Du
mper(\@a)"
$VAR1 = [
2, # device
0, # inode
16895, # mode = 0x41FF = 040777
1, # nlink
0, # uid
0, # gid
2, # rdev
0, # size
1340557931, # atime
1340557931, # mtime
1336337436, # ctime
'', # blocksize
'' # blocks
];
C:\Users\alex>
Mode 0777 happens on Windows only for executables (by extension) and for directories. The bit 040000 looks like the directory flag. This fits the picture, because there is no executable extension in the file name.
Maybe some routine burried deep inside Perl, MinGW or Windows unquotes filenames? Let's look at the stat() output for "." and "..":
C:\Users\alex>perl -MData::Dumper -E "for $x (chr(34).chr(34),'.','..'
+) { @a=stat($x); say Dumper(\@a) }"
$VAR1 = [
2,
0,
16895,
1,
0,
0,
2,
0,
1340557931,
1340557931,
1336337436,
'',
''
];
$VAR1 = [
2,
0,
16895,
1,
0,
0,
2,
0,
1340557931,
1340557931,
1336337436,
'',
''
];
$VAR1 = [
2,
0,
16749,
1,
0,
0,
2,
0,
1339842184,
1339842184,
1247541608,
'',
''
];
C:\Users\alex>
Exact match for ".". Are quotes removed automatically?
C:\Users\alex>perl -MData::Dumper -E "@a=stat(chr(34).'Desktop'.chr(34
+)); say Dumper(\@a)"
$VAR1 = [];
C:\Users\alex>perl -MData::Dumper -E "@a=stat(''); say Dumper(\@a)"
$VAR1 = [];
C:\Users\alex>perl -MData::Dumper -E "@a=stat(chr(34).'..'.chr(34)); s
+ay Dumper(\@a)"
$VAR1 = [];
C:\Users\alex>perl -MData::Dumper -E "@a=stat(chr(34).'.'.chr(34)); sa
+y Dumper(\@a)"
$VAR1 = [];
C:\Users\alex>
No. I have no clue why '""' is treated like '.' on Windows.
What happens when I call stat() from C/MinGW?
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char ** argv)
{
struct stat st;
printf("stat(\"\") = %i\n",stat("\"\"",&st));
return 0;
}
X:\>gcc -o stattest.exe stattest.c
X:\>stattest
stat("") = -1
X:\>
So, it's very likely neither Windows nor MinGW, so it must be Perl.
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
|