From a71e0af25544fd2486e57ea51c6d05abdbf44c3e Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 19 Jun 2012 01:27:26 -0400 Subject: stdio: handle file position correctly at program exit for seekable files, posix imposed requirements on the offset of the underlying open file description after a stream is closed. this was correctly handled (as a side effect of the unconditional fflush call) when streams were explicitly closed by fclose, but was not handled correctly at program exit time, where fflush(0) was being used. the weak symbol hackery is to pull in __stdio_exit if either of __toread or __towrite is used, but avoid calling it twice so we don't have to keep extra state. the new __stdio_exit is a streamlined fflush variant that avoids performing any unnecessary operations and which never unlocks the files or open file list, so we can be sure no other threads write new data to a stream's buffer after it's already flushed. --- src/stdio/__towrite.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/stdio/__towrite.c') diff --git a/src/stdio/__towrite.c b/src/stdio/__towrite.c index 4bf96f4d..ba67e0df 100644 --- a/src/stdio/__towrite.c +++ b/src/stdio/__towrite.c @@ -17,8 +17,9 @@ int __towrite(FILE *f) return 0; } -/* Link flush-on-exit code iff any stdio write functions are linked. */ -void __fflush_on_exit() +const int __towrite_used = 1; + +void __flush_on_exit() { - fflush(0); + __stdio_exit(); } -- cgit v1.2.1