I am trying to get the correct error code out of errno when opening a directory as a file, both with fopen as well as with ifstream.open(). I expect EISDIR, I get EACCES.
I am compiling (and executing) with the MSVC 12.0 toolchain on Windows 7 x64.
I have been reading in article (https://gehrcke.de/2011/06/reading-files-in-c-using-ifstream-dealing-correctly-with-badbit-failbit-eofbit-and-perror/) where the author got the output "stream failbit (or badbit). error state: Is a directory".
I compiled the authors files with GCC 4.6 (or above, not sure atm) and on passing a directory as argument I get EACCES as well.
I know there is no easy way of telling whether a disk object is a directory on windows, so not getting EISDIR is not too surprising.
Is there anything that can be done about it (getting EISDIR on windows, that is)? Are there other errno's that behave in a similar (unexpected) way?
EINVAL
noris_a_directory
symbols referenced in the Microsoft C libraries (I've checked the VS 12.0 one and the Universal CRT as used by VS 14.0) anywhere but the definitions themselves, i.e. they're there but they are not used. Alternatives (MinGW etc.) link to the msvcrt.dll and you've already confirmed that it doesn't behave the way you want either. – cynicGetFileAttributes( object ) & FILE_ATTRIBUTE_DIRECTORY
. And MSVC has_stat()
or_fstat
, seest_mode & _S_IFDIR
. – MSalters