[m-dev.] EISDIR and file opening
paul at bone.id.au
Fri Sep 2 20:32:52 AEST 2016
On Fri, Sep 02, 2016 at 05:23:44PM +1000, Peter Wang wrote:
> 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.
That FreeBSD could lead to even more confusing behaviour makes me want to
change this even more.
> 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.
Assuming that it makes another syscall we could reduce this impact by only
doing this on FreeBSD systems, and possibly also Linux systems (if an open
error is better than a read error).
More information about the developers