[PATCH] newlib: fix fseek optimization with SEEK_CUR

Bastien Bouclet bastien.bouclet@gmail.com
Wed Nov 13 20:36:00 GMT 2019

Hi Corinna,

Thank you for your answer.

> I checked this against upstream BSD versions.  OpenBSD and NetBSD
> operate like our code, including the flush, while FreeBSD uses its
> internal ftello and never flushed since the repository import back in
> 1994.

One difference I've noticed is that fflush does not invalidate the
stream read buffer in the BSD versions of libc.  In newlib this was
introduced in commit a8ef755c2776b8da4ea386360c1df74ce268c165.  Which
is probably why OpenBSD and NetBSD can call fflush in fseek with

> Can we be sure this works as desired on append streams as well?

Regarding the append streams, it's worth noting there is another call
to fflush at the beginning of fseek in that case.  I've written a small
test program to verify they did not regress in simple cases.

> Also, given that this is changing very basic code, nobody is unaffected.

I would like to see the performance issue fixed one way or another.
The systems I target do not have a page cache, the extra reads have a
noticeable impact on user experience.  Another other option could be
having a compile time option for disabling the code in fflush that
forces a disk access on the next read.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: stdio-append.c
Type: text/x-csrc
Size: 1559 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20191113/5cedacc7/attachment.bin>

More information about the Newlib mailing list