On Tue, Nov 2, 2021 at 3:17 PM RVP <r...@sdf.org> wrote: > > On Tue, 2 Nov 2021, Christos Zoulas wrote: > > > In article <a91717c9-3b97-2756-5b73-81d5dee...@sdf.org>, > > RVP <r...@sdf.org> wrote: > >> > >> This looks like a useful behaviour to add to the libc close routines. > > > > I agree!
FWIW at least MUSL seems to be just doing an fflush(), which might be the part where I thought NetBSD's implementation might be diverging from the standard[1] where it says in calls to fseek() in 7.21.9.2.4 "For a text stream, either offset shall be zero, or offset shall be a value returned by an earlier successful call to the ftell function on a stream associated with the same file and whence shall be SEEK_SET." There is also a mention somewhere else that fflush() is required to "write" the position, which seems to imply that fflush(stdin) might have been what was missing (but didn't help) in my original example[2]. Note that the way the wording is done in that paragraph, it might seem to imply that the position is a property of the file and not of the FILE, so you could have more than one FILE pointing to the same fd, and any fseek on it should be visible to them all. > diff -urN stdio.orig/findfp.c stdio/findfp.c > --- stdio.orig/findfp.c 2012-03-27 15:05:42.000000000 +0000 > +++ stdio/findfp.c 2021-11-02 21:46:29.767257736 +0000 > @@ -207,8 +207,10 @@ > void > _cleanup(void) > { > - /* (void) _fwalk(fclose); */ > + (void) _fwalk(fclose); > +#if 0 > (void) fflush(NULL); /* `cheating' */ > +#endif > } > > Carlo, can you see if that works with your use-case? I only have a slow OpenBSD VM with current to test, so I am building a port of your patch there (which seems will take several more hours to build), I kept the "cheating" part there though, so not sure how much useful my answer would be, but I expect it to work. Carlo [1] https://web.archive.org/web/20181230041359/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf [2] https://gist.github.com/carenas/7c13147ef10365bec2595c9e87102ae7