bug-coreutils
[Top][All Lists]
Advanced

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

Re: more gcc warnings


From: Eric Blake
Subject: Re: more gcc warnings
Date: Thu, 14 Jul 2005 23:26:34 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Paul Eggert <eggert <at> CS.UCLA.EDU> writes:
> 
> I dislike all that isatty stuff -- is there some way that we could
> easily remove it from the mainline sources, and put it in config.h or
> somewhere we we don't have to see it?  For example, can we replace this:
> 
>   if (O_BINARY && ! isatty (STDIN_FILENO))
>     freopen (NULL, "rb", stdin);
> 
> with this:
> 
>   if (O_BINARY)
>     freopen (NULL, "rb", stdin);

As it is, you will need a wrapper for freopen.  At least Solaris 8 and cygwin 
1.5.18 choke on the program below, dying with EFAULT instead of changing the 
mode of stdin as POSIX requires.  While I like your change stylistically, it 
has broken coreutils CVS head on cygwin until we have a replacement freopen 
that can handle a NULL filename when the platform won't.

#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;
}

$ uname -a
CYGWIN_NT-5.0 eblake 1.5.19s(0.132/4/2) 20050705 16:21:45 i686 unknown unknown 
Cygwin
$ ./foo
file is null, errno 14:Bad address

$ uname -a
SunOS perth 5.8 Generic_108528-15 sun4u sparc SUNW,Sun-Blade-100 Solaris
$ ./foo
file is null, errno 14:Bad address

--
Eric Blake







reply via email to

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