public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* bug in freopen
@ 2005-07-14 23:13 Eric Blake
  2005-07-14 23:32 ` Christopher Faylor
  2005-07-15 10:38 ` Dave Korn
  0 siblings, 2 replies; 8+ messages in thread
From: Eric Blake @ 2005-07-14 23:13 UTC (permalink / raw)
  To: cygwin, newlib

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.

--
Eric Blake

--
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/

^ permalink raw reply	[flat|nested] 8+ messages in thread
* RE: bug in freopen
@ 2005-07-15  7:26 Schwarz, Konrad
  0 siblings, 0 replies; 8+ messages in thread
From: Schwarz, Konrad @ 2005-07-15  7:26 UTC (permalink / raw)
  To: Eric Blake, cygwin, newlib


> -----Original Message-----
> From: newlib-owner@sources.redhat.com 
> [mailto:newlib-owner@sources.redhat.com] On Behalf Of Eric Blake
> Sent: Friday, July 15, 2005 1:14 AM
> To: cygwin@cygwin.com; newlib@sourceware.org
> Subject: bug in freopen
> 
> 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

Just to be pedantic: POSIX allows system interfaces to set <errno> to
values additional to those documented in the standard, so this in itself
is not necessarily a bug.

Of course, freopen() should not be calling open() with NULL, it appears
this case has not been implemented in newlib. 

> 
> #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.
> 
> --
> Eric Blake
> 

--
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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-07-19 12:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-14 23:13 bug in freopen Eric Blake
2005-07-14 23:32 ` Christopher Faylor
2005-07-15  3:49   ` Eric Blake
2005-07-15 14:12     ` Christopher Faylor
2005-07-15 10:38 ` Dave Korn
2005-07-18 19:11   ` Jeff Johnston
2005-07-19 12:08     ` Dave Korn
2005-07-15  7:26 Schwarz, Konrad

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).