file/open: check if directory#1532
Conversation
Adds fstat() directory test after fopen(), which can return non-NULL when passed a directory name on Linux
|
As an afterthought, it's not great that this introduces a different message for the same error on multiple platforms (ie, Windows says 'could not find file') |
|
I can confirm that this does improve the error message on my machine as well |
Should use fileno() instead of direct
|
While I like the error message, something bothers me about making an extra system call every time we open a file. That said, python does the same thing, and there is always |
|
Being a system call didn't occur to me, but I agree, though looking at the field it seems everyone is fine doing this, which is crazy to me...open/fopen give multiple options to ensure a target is definitely a directory; I'm very curious what the use case is to 'read' a directory in binary...everything I've read suggests nobody actually does that. Alternatively, as Jakob originally suggested just save the file name for use later if an error pops up. I assume nobody can open enough files to make the memory usage matter? |
Adds fstat directory test after fopen, which can return non-NULL when passed a directory name on Linux.
Tested on Ubuntu 22.04 (+valgrind), & Windows 10
Should close #1530