in reply to Re^4: 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

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?

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

Replies are listed 'Best First'.
Re^6: true from (-e "") on Windoze (" is an illegal filename character
by afoken (Chancellor) on Jul 05, 2012 at 20:13 UTC
    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:

      C:\test>type stat.c #include <windows.h> #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_nlin +k, 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_nlin +k, buf2.st_rdev, buf2.st_size, buf2.st_uid ); return 1; } C:\test>cl /W3 stat.c Microsoft (R) C/C++ Optimizing Compiler Version 15.00.21022.08 for x64 Copyright (C) Microsoft Corporation. All rights reserved. stat.c stat.c(8) : warning C4101: 'fa' : unreferenced local variable Microsoft (R) Incremental Linker Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. /out:stat.exe stat.obj C:\test>stat c:\test for ""; stat returned: 0 gid: 0 atime:4ff5f775 ctime:49bba448 drive:2 inode:0 mode:41ff mtime:4ff5f775 nlink:1 rdev:2 size:0 uid:0 For c:\test; stat returned: 0 gid: 0 atime:4ff5f775 ctime:49bba448 drive:2 inode:0 mode:41ff mtime:4ff5f775 nlink:1 rdev:2 size:0 uid:0 C:\test>dumpbin /imports stat.exe Microsoft (R) COFF/PE Dumper Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file stat.exe File Type: EXECUTABLE IMAGE Section contains the following imports: KERNEL32.dll 14000D000 Import Address Table 14000EF68 Import Name Table 0 time date stamp 0 Index of first forwarder reference 1E7 GetLastError 11B FindClose 112 FileTimeToSystemTime 111 FileTimeToLocalFileTime 1BC GetDriveTypeA 11F FindFirstFileA 171 GetCommandLineA 39E RtlUnwindEx DB EnterCriticalSection 2EE LeaveCriticalSection 43B TerminateProcess 1AB GetCurrentProcess 44C UnhandledExceptionFilter 423 SetUnhandledExceptionFilter 2D0 IsDebuggerPresent 39F RtlVirtualUnwind 398 RtlLookupFunctionEntry 391 RtlCaptureContext 1DE GetFullPathNameA 2A6 HeapFree 1A9 GetCurrentDirectoryA 1FA GetModuleHandleW 42F Sleep 222 GetProcAddress 106 ExitProcess 49B WriteFile 23E GetStdHandle 1F5 GetModuleFileNameA 14C FreeEnvironmentStringsA 1C1 GetEnvironmentStrings 14D FreeEnvironmentStringsW 488 WideCharToMultiByte 1C3 GetEnvironmentStringsW 3F4 SetHandleCount 1D9 GetFileType 23C GetStartupInfoA C0 DeleteCriticalSection D7 EncodePointer B9 DecodePointer 140 FlsGetValue 141 FlsSetValue 13F FlsFree 3F8 SetLastError 1AF GetCurrentThreadId 13E FlsAlloc 2AA HeapSetInformation 2A4 HeapCreate 353 QueryPerformanceCounter 26A GetTickCount 1AC GetCurrentProcessId 253 GetSystemTimeAsFileTime 15D GetCPInfo 154 GetACP 214 GetOEMCP 2DA IsValidCodePage 26F GetTimeZoneInformation 2E0 LCMapStringA 319 MultiByteToWideChar 2E2 LCMapStringW 2F0 LoadLibraryA 2BA InitializeCriticalSectionAndSpinCount 2A2 HeapAlloc 2A9 HeapReAlloc 185 GetConsoleCP 197 GetConsoleMode 143 FlushFileBuffers 240 GetStringTypeA 243 GetStringTypeW 1E9 GetLocaleInfoA 3EC SetFilePointer 2AB HeapSize 44 CloseHandle 490 WriteConsoleA 19B GetConsoleOutputCP 49A WriteConsoleW 40A SetStdHandle 7A CreateFileA 53 CompareStringA 56 CompareStringW 3DD SetEnvironmentVariableA Summary 4000 .data 1000 .pdata 3000 .rdata C000 .text

      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?