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:

      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?