[m-dev.] EISDIR and file opening

Peter Wang novalazy at gmail.com
Fri Sep 2 17:23:44 AEST 2016


On Wed, 31 Aug 2016 13:52:53 +1000, Paul Bone <paul at bone.id.au> wrote:
> 
> I noticed recently that, at least on my Linux system, opening with fopen() a
> directory will succeed.  Errors will be returned when you attempt to read
> from the returned file object.
> 
> Should the library code check that it has not just opened a directory within
> the open code?  Rather than waiting for the caller to attempt to read from
> the file?

Hi Paul,

For what it's worth, FreeBSD still allows read() on directories.
I'm having trouble seeing the utility, though.  In general, I would
veer towards not imposing additional restrictions on top of the OS,
but Mercury streams are their own abstraction.

An argument against the directory check is that it adds an additional
system call (I assume) for every file opened, when most applications
should be able to handle the EISDIR like any other error.

Peter


More information about the developers mailing list