[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mingw fopen bug

From: Eric Blake
Subject: mingw fopen bug
Date: Mon, 22 Sep 2008 21:55:17 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

According to POSIX, open(".",O_RDONLY) must succeed.  And if I'm reading POSIX 
correctly, fopen(".","r") must also succeed, since it should have the same 
effect as open(".",O_RDONLY).  It is only on subsequent attempts to read() from 
a directory that POSIX then allows, but not requires, a failure of EISDIR (at 
least Linux, Solaris, and cygwin make read() of a directory fail with EISDIR; 
OpenBSD allows the read() to succeed but always with 0 bytes [ie. the directory 
is indistinguishable from an empty file], and older platforms, such as Elbert 
Pol's report for EMX os/2, actually read raw bytes that could then be used to 
populate struct dirent).

But on mingw, fopen(".","r") fails with EACCES.  Is it worth trying to enhance 
the gnulib fopen module to work around this bug, possibly in tandem with 
dirfd/fdopendir replacements (fchdir module), such that mingw can be made to 
open a FILE stream around a directory, even though such a stream cannot be 
directly read from?  Adding such a workaround would allow code like this to 
work on mingw:

FILE *f = fopen (".", "r");
DIR *d = fdopendir (fileno (f));
readdir (d);

although that seems a bit contrived (why not use opendir() in the first place?).

reply via email to

[Prev in Thread] Current Thread [Next in Thread]