This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: bug in freopen


On Thu, Jul 14, 2005 at 11:13:35PM +0000, Eric Blake wrote:
>POSIX requires that freopen(NULL, mode, f) reopen f in the new
>mode, and allows implementations the option of not even closing
>f in the first place.  But in cygwin, it is failing with EFAULT, which is
>not even one of the errors allowed by POSIX.
>
>http://www.opengroup.org/susv3xsh/freopen.html
>
>#include <stdio.h>
>#include <errno.h>
>int main(void)
>{
>   FILE* f = freopen (NULL, "rb", stdin); /* Ensure that stdin is binary */
>   printf ("file is %s, errno %d:%s\n", f ? "good" : "null", errno,
>           strerror(errno));
>   return 0;
>}
>
>CVS coreutils recently switched to this idiom, replacing its former
>use of the nonstandard <io.h> and setmode() with something
>that is required by the standards.  But until this bug is fixed, CVS
>coreutils will not work with cygwin.  The strace in cygwin shows
>that newlib tried to perform open(NULL), which is the cause of
>the EFAULT.

Hmm.  It should be pretty simple to just make this always fail with
EBADF.  That seems to be a valid thing to do as far as SUSv3 is
concerned.

I am curious, though, as to the rationale behind this change.  I just
tried this with -mno-cygwin and it dies with a ENOENT.  So, they
apparently removed windows-specific code and replaced it with code
that doesn't work on windows...

cgf

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]