[PATCH v2] Add a new fwrite test for read-only streams

Maciej W. Rozycki macro@redhat.com
Tue Sep 10 16:36:12 GMT 2024


On Tue, 10 Sep 2024, Maciej W. Rozycki wrote:

> > diff --git a/stdio-common/tst-fwrite-ro.c b/stdio-common/tst-fwrite-ro.c
> > new file mode 100644
> > index 0000000000..b15753d4c4
> > --- /dev/null
> > +++ b/stdio-common/tst-fwrite-ro.c
> [...]
> > +  /* Try to write to the temporary file with nmemb = 0, then check that
> > +     fwrite returns 0.  No errors are expected from this.  */
> > +  TEST_COMPARE (fwrite ("a", 1, 0, f), 0);
> > +  TEST_COMPARE (ferror (f), 0);
> 
>  Is it not a compliance bug though?  ISO C has this:
> 
> "The fwrite function returns the number of elements successfully written, 
> which will be less than nmemb only if a write error is encountered.  If 
> size or nmemb is zero, fwrite returns zero and the state of the stream 
> remains unchanged."

 Not my day obviously, as nmemb is zero here.  Please consider my concern 
withdrawn.  Sorry for the confusion.

  Maciej



More information about the Libc-alpha mailing list