[PATCH v2] libio: Add test case for fflush

Frederic Berat fberat@redhat.com
Thu Nov 7 10:24:43 GMT 2024


On Thu, Nov 7, 2024 at 11:07 AM Florian Weimer <fweimer@redhat.com> wrote:

> * Frederic Berat:
>
> > On Thu, Nov 7, 2024 at 10:27 AM Florian Weimer <fweimer@redhat.com>
> wrote:
> >
> >  * Frederic Berat:
> >
> >  > On Wed, Nov 6, 2024 at 6:10 PM Florian Weimer <fweimer@redhat.com>
> wrote:
> >  >
> >  >  * Frédéric Bérat:
> >  >
> >  >  > I also tested the following:
> >  >  >       char s[3] = "";
> >  >  >       fgets (s, 2, FILE);
> >  >  >       ungetc (s[1], FILE);
> >  >  >       fflush (FILE);
> >  >  >       pos = lseek (SEEK_CUR);
> >  >  >
> >  >  > Which gives a `pos` value of 2.
>
> > Without unget:
> > fgetc: Position in stream before fflush: 1424
> > fgetc: Position in stream after fflush: 2
>
> That's the only value 2 in the test, and it's using fgetc, not fgets?
>

Correct, the difference with my original test resides in the content size
of the file, here I tried with the source code, which has a size of 1424
bytes, while in my original test, the text file had a size of 3 bytes.
My original assumption was that there was a difference by 1, but actually
with fgets, the position seems to be set to file (buffer?) content size - 1.


>
> Thanks,
> Florian
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20241107/9dc81f3d/attachment.htm>


More information about the Libc-alpha mailing list