Mail Archives: djgpp-workers/2013/07/17/22:50:20
> Date: Wed, 17 Jul 2013 22:47:28 +0200
> From: Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
>
> 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.
- Raw text -