Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by afoken (Parson)
on Jul 03, 2012 at 19:22 UTC ( #979760=note: print w/ replies, xml ) Need Help??


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

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". ;-)


Comment on Re^4: true from (-e "") on Windoze (" is an illegal filename character
Select or Download Code
Re^5: true from (-e "") on Windoze (" is an illegal filename character
by Anonymous Monk on Jul 03, 2012 at 19:44 UTC

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

      X:\>objdump -p 979536.exe 979536.exe: file format pei-x86-64 Characteristics 0x27 relocations stripped executable line numbers stripped large address aware Time/Date Thu Jul 05 21:33:01 2012 Magic 020b (PE32+) MajorLinkerVersion 2 MinorLinkerVersion 21 SizeOfCode 00002200 SizeOfInitializedData 00001400 SizeOfUninitializedData 00000a00 AddressOfEntryPoint 00000000000014e0 BaseOfCode 0000000000001000 ImageBase 0000000000400000 SectionAlignment 0000000000001000 FileAlignment 0000000000000200 MajorOSystemVersion 4 MinorOSystemVersion 0 MajorImageVersion 0 MinorImageVersion 0 MajorSubsystemVersion 5 MinorSubsystemVersion 2 Win32Version 00000000 SizeOfImage 00022000 SizeOfHeaders 00000600 CheckSum 000268cb Subsystem 00000003 (Windows CUI) DllCharacteristics 00000000 SizeOfStackReserve 0000000000200000 SizeOfStackCommit 0000000000001000 SizeOfHeapReserve 0000000000100000 SizeOfHeapCommit 0000000000001000 LoaderFlags 00000000 NumberOfRvaAndSizes 00000010 The Data Directory Entry 0 0000000000000000 00000000 Export Directory [.edata (or where e +ver we fou nd it)] Entry 1 0000000000007000 0000082c Import Directory [parts of .idata] Entry 2 0000000000000000 00000000 Resource Directory [.rsrc] Entry 3 0000000000000000 00000000 Exception Directory [.pdata] Entry 4 0000000000000000 00000000 Security Directory Entry 5 0000000000000000 00000000 Base Relocation Directory [.reloc] Entry 6 0000000000000000 00000000 Debug Directory Entry 7 0000000000000000 00000000 Description Directory Entry 8 0000000000000000 00000000 Special Directory Entry 9 0000000000009000 00000028 Thread Storage Directory [.tls] Entry a 0000000000000000 00000000 Load Configuration Directory Entry b 0000000000000000 00000000 Bound Import Directory Entry c 0000000000007204 000001c8 Import Address Table Directory Entry d 0000000000000000 00000000 Delay Import Directory Entry e 0000000000000000 00000000 CLR Runtime Header Entry f 0000000000000000 00000000 Reserved There is an import table in .idata at 0x407000 The Import Tables (interpreted .idata section contents) vma: Hint Time Forward DLL First Table Stamp Chain Name Thunk 00007000 0000703c 00000000 00000000 0000779c 00007204 DLL Name: KERNEL32.dll vma: Hint/Ord Member-Name Bound-To 73cc 134 DeleteCriticalSection 73e4 157 EnterCriticalSection 73fc 327 GetCurrentProcess 7410 328 GetCurrentProcessId 7426 331 GetCurrentThreadId 743c 373 GetLastError 744c 387 GetModuleHandleA 7460 420 GetProcAddress 7472 443 GetStartupInfoA 7484 462 GetSystemTimeAsFileTime 749e 483 GetTickCount 74ae 551 InitializeCriticalSection 74ca 591 LeaveCriticalSection 74e2 595 LoadLibraryW 74f2 673 QueryPerformanceCounter 750c 721 RtlAddFunctionTable 7522 722 RtlCaptureContext 7536 729 RtlLookupFunctionEntry 7550 736 RtlVirtualUnwind 7564 850 SetUnhandledExceptionFilter 7582 862 Sleep 758a 870 TerminateProcess 759e 877 TlsGetValue 75ac 886 UnhandledExceptionFilter 75c8 910 VirtualProtect 75da 912 VirtualQuery 00007014 00007114 00000000 00000000 00007820 000072dc DLL Name: msvcrt.dll vma: Hint/Ord Member-Name Bound-To 75ea 78 __dllonexit 75f8 81 __getmainargs 7608 82 __initenv 7614 83 __iob_func 7622 90 __lconv_init 7632 96 __set_app_type 7644 98 __setusermatherr 7658 114 _acmdln 7662 121 _amsg_exit 7670 139 _cexit 767a 231 _fmode 7684 297 _initterm 7690 400 _lock 7698 564 _onexit 76a2 653 _stat64 76ac 732 _unlock 76b6 932 abort 76be 946 calloc 76c8 956 exit 76d0 971 fprintf 76da 978 free 76e2 989 fwrite 76ec 1034 malloc 76f6 1042 memcpy 7700 1050 printf 770a 1072 signal 7714 1092 strlen 771e 1095 strncmp 7728 1127 vfprintf 00007028 00000000 00000000 00000000 00000000 00000000 X:\>

      Process Explorer shows that BrowserUK's test program uses msvcrt.dll from C:\Windows\System32\msvcrt.dll. This DLL is part of Windows 7, with file and product version both set to 7.0.7601.17744. It seems that msvcrt.dll loads several other DLLs (apisetschema.dll 6.1.7600.16385, kernelbase.dll 6.1.7601.17651, ntdll.dll 6.1.7601.17725) all from C:\Windows\System32, all from Microsoft. The program itself also uses kernel32.dll 6.1.7601.17651, of course from C:\Windows\System32, delivered by Microsoft. No other DLLs are loaded, and not a single DLL comes from the MinGW installation that came with Straberry Perl.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re^5: true from (-e "") on Windoze (" is an illegal filename character
by BrowserUk (Pope) on Jul 03, 2012 at 19:47 UTC
    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?

      What do you expect the gcc CRT to emulate?

      Nothing. stat (via _stat64) is available from msvcrt.dll, as documented by Microsoft. For the return value, MS writes:

      Each of these functions returns 0 if the file-status information is obtained. A return value of 1 indicates an error, in which case errno is set to ENOENT, indicating that the filename or path could not be found. A return value of EINVAL indicates an invalid parameter; errno is also set to EINVAL in this case.

      So, let's have a look at errno:

      #include <stdio.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> int main( int argc, char **argv ) { struct _stat buf1, buf2; char *file = "\"\""; printf("ENOENT=%d EINVAL=%d\n",ENOENT,EINVAL); 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\nerrno:%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, errno ); 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\nerrno:%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, errno ); return 1; }

      Output:

      X:\>979536.exe ENOENT=2 EINVAL=22 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 errno:2 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 errno:22 X:\>979536.exe . ENOENT=2 EINVAL=22 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 errno:2 For .; stat returned: 0 gid: 0 atime:12ce97f0 ctime:12ce97f0 drive:23 inode:0 mode:41ff mtime:12ce97f0 nlink:1 rdev:23 size:0 uid:0 errno:2 X:\>979536.exe 979536.exe ENOENT=2 EINVAL=22 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 errno:2 For 979536.exe; stat returned: 0 gid: 0 atime:4ff4bce0 ctime:4ff5ebed drive:23 inode:0 mode:81ff mtime:4ff5f368 nlink:1 rdev:23 size:121535 uid:0 errno:2 X:\>

      I think this is what one should expect. The file "" does not exist, and NULL is an invalid parameter. For the current directory and the exe file, stat() returns 0, as expected, and errno is not touched at all, so it stays 2 from the previously failed stat().

      Alexander

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

        Sorry. But you are still wrong.

        Trying to draw conclusions about what the MS compiler does, from what you can observe from compiling similar code using the Mingw; is like trying to draw conclusions about the AC Cobra from driving a DAX 427 kit car.

        Observe:

        That code, compiled with an MS compiler, doesn't import anything from msvcrt.dll!

        I'll let you work out why for yourself.


        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?

Re^5: true from (-e "") on Windoze (" is an illegal filename character
by Anonymous Monk on Jul 03, 2012 at 19:48 UTC
    $ 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://979760]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2014-09-23 03:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls