X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f X-Recipient: djgpp-workers AT delorie DOT com Date: Thu, 18 Jul 2013 05:49:50 +0300 From: Eli Zaretskii Subject: Re: Set _IOERR if the file stream has been opened in wrong mode. In-reply-to: <51E702E0.3010809@gmx.de> X-012-Sender: halo1 AT inter DOT net DOT il To: djgpp-workers AT delorie DOT com Message-id: <83fvvc1t0x.fsf@gnu.org> References: <51E5D0C6 DOT 1060404 AT gmx DOT de> <83y5951a79 DOT fsf AT gnu DOT org> <51E702E0 DOT 3010809 AT gmx DOT de> Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > Date: Wed, 17 Jul 2013 22:47:28 +0200 > From: Juan Manuel Guerrero > > According to http://pubs.opengroup.org/onlinepubs/009695399/functions/fgets.html > RETURN VALUE > > Upon successful completion, fgets() shall return s. If the stream is at end-of-file, > the end-of-file indicator for the stream shall be set and fgets() shall return a null > pointer. If a read error occurs, the error indicator for the stream shall be set, > fgets() shall return a null pointer. > > > According to http://pubs.opengroup.org/onlinepubs/009695399/functions/fputs.html > RETURN VALUE > > Upon successful completion, fputs() shall return a non-negative number. Otherwise, > it shall return EOF, set an error indicator for the stream. > > > According to http://pubs.opengroup.org/onlinepubs/009695399/functions/fread.html > RETURN VALUE > > Upon successful completion, fread() shall return the number of elements successfully > read which is less than nitems only if a read error or end-of-file is encountered. > If size or nitems is 0, fread() shall return 0 and the contents of the array and the > state of the stream remain unchanged. Otherwise, if a read error occurs, the error > indicator for the stream shall be set > > > According to http://pubs.opengroup.org/onlinepubs/009695399/functions/fwrite.html > RETURN VALUE > > The fwrite() function shall return the number of elements successfully written, > which may be less than nitems if a write error is encountered. If size or nitems > is 0, fwrite() shall return 0 and the state of the stream remains unchanged. > Otherwise, if a write error occurs, the error indicator for the stream shall be set, > > > For IEEE Std 1003.1-2001-conforming systems all the functions also shall set errno. Thanks, but I've already read all that, and found nothing about reading from a stream open as "w". Who said that is an error? > It is a matter of fact that the sample code posted in the previous mail > behaves as described by me for linux and cygwin. And this behavior is > exploited by other programs like lua. I have inspected __getc, __putc, > fwrite and fread and neither of them set EOF. filbuf.c sets EOF when __getc returns -1. > BTW as can be seen for fgets if the stream is at end-of-file, the end-of-file > indicator for the stream shall be set apart from returning a NULL pointer. It already does that, AFAICS.