Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: true from (-e "") on Windoze (" is an illegal filename character

by afoken (Prior)
on Jul 02, 2012 at 20:09 UTC ( #979531=note: print w/ replies, xml ) Need Help??


in reply to Re: true from (-e "") on Windoze (" is an illegal filename character
in thread true from (-e "") on Windoze

And when you search for the empty string, dir "", you get everything.

dir is not stat().

The quote " character is illegal in Windows filenames. Therefore, what you are passing to the OS is taken as the empty string.

No. If it would, stat() in the C example would return 0 (success), not -1 (error).

You are effectively asking, is there anything in the current directory. Which will always be true.

Wrong conclusion.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)


Comment on Re^2: true from (-e "") on Windoze (" is an illegal filename character
Replies are listed 'Best First'.
Re^3: true from (-e "") on Windoze (" is an illegal filename character
by BrowserUk (Pope) on Jul 02, 2012 at 21:01 UTC

    Sorry, but you are wrong. Here is the proof:

    #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> int main( int argc, char **argv ) { struct _stat buf1, buf2; char *file = "\"\""; printf( "for %s; stat returned: %d\n", file, _stat( file, &buf1 ) +); printf( "gid: %d\natime:%I64x\nctime:%I64x\ndrive:%d\n" "inode:%d\nmode:%x\nmtime:%I64x\nnlink:%d\nrdev:%d\n" "size:%d\nuid:%d\n", buf1.st_gid, buf1.st_atime, buf1.st_ctime, buf1.st_dev, buf1.st_ino, buf1.st_mode, buf1.st_mtime, buf1.st_nlink, buf1. +st_rdev, buf1.st_size, buf1.st_uid ); printf( "\nFor %s; stat returned: %d\n", argv[1], _stat( argv[1], +&buf2 ) ); printf( "gid: %d\natime:%I64x\nctime:%I64x\ndrive:%d\n" "inode:%d\nmode:%x\nmtime:%I64x\nnlink:%d\nrdev:%d\n" "size:%d\nuid:%d\n", buf2.st_gid, buf2.st_atime, buf2.st_ctime, buf2.st_dev, buf2.st_ino, buf2.st_mode, buf2.st_mtime, buf2.st_nlink, buf2. +st_rdev, buf2.st_size, buf2.st_uid ); return 1; }

    That code first stats the filename '""'; then it stats the pathname passed from the command line in argv1.

    Run passing the path of the current directory, both sets of stats are identical:

    C:\test>stat c:\test for ""; stat returned: 0 gid: 0 atime:4ff203c6 ctime:49bba448 drive:2 inode:0 mode:41ff mtime:4ff203c6 nlink:1 rdev:2 size:0 uid:0 For c:\test; stat returned: 0 gid: 0 atime:4ff203c6 ctime:49bba448 drive:2 inode:0 mode:41ff mtime:4ff203c6 nlink:1 rdev:2 size:0 uid:0

    Explain that in any way other than '""' is being taken to mean 'the current directory'?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      I don't know what combination of compiler and OS you use, but on my system (Win7 Ult + Strawberry 5.14.2 x64), your unmodified code clearly shows that stat() fails:

      X:\>gcc -Wall --pedantic -o 979536.exe 979536.c 979536.c: In function 'main': 979536.c:18: warning: ISO C does not support the 'I64' ms_printf lengt +h modifier 979536.c:18: warning: ISO C does not support the 'I64' ms_printf lengt +h modifier 979536.c:18: warning: ISO C does not support the 'I64' ms_printf lengt +h modifier 979536.c:18: warning: format '%d' expects type 'int', but argument 11 +has type '_off_t' 979536.c:29: warning: ISO C does not support the 'I64' ms_printf lengt +h modifier 979536.c:29: warning: ISO C does not support the 'I64' ms_printf lengt +h modifier 979536.c:29: warning: ISO C does not support the 'I64' ms_printf lengt +h modifier 979536.c:29: warning: format '%d' expects type 'int', but argument 11 +has type '_off_t' X:\>979536.exe for ""; stat returned: -1 gid: 0 atime:0 ctime:0 drive:0 inode:0 mode:0 mtime:0 nlink:0 rdev:0 size:0 uid:0 For (null); stat returned: -1 gid: 0 atime:0 ctime:0 drive:0 inode:0 mode:0 mtime:0 nlink:0 rdev:0 size:0 uid:0 X:\>gcc --version gcc (GCC) 4.4.7 20111023 (prerelease) [svn/rev.180339 - mingw-w64/oz] Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There i +s NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR +POSE. X:\>

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        I don't know what combination of compiler and OS you use

        MS compiler; Vista 64-bit.

        but on my system (Win7 Ult + Strawberry 5.14.2 x64),

        What do you expect the gcc CRT to emulate?


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

        Maybe gcc (  objdump -p ..dllorexe... |grep DLL.Name ---- libgcc_s_dw2-1.dll ) supplies its own stat?

        $ a.exe C:\windows for ""; stat returned: 0 gid: 0 atime:4f7ce8bb4ff34c63 ctime:3 drive:16895 inode:1341344867 mode:1 mtime:3 nlink:0 rdev:0 size:2009291924 uid:2009310510 For C:\windows; stat returned: 0 gid: 0 atime:44b567444ff34280 ctime:2 drive:16895 inode:1340498070 mode:1 mtime:2 nlink:0 rdev:0 size:2009291924 uid:0 $ objdump -p a.exe |grep DLL.Name DLL Name: KERNEL32.dll DLL Name: msvcrt.dll $ gcc --version gcc (GCC) 4.7.0 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There i +s NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR +POSE.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://979531]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2015-07-28 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls