path: root/src/exit
diff options
authorRich Felker <>2012-06-19 01:27:26 -0400
committerRich Felker <>2012-06-19 01:27:26 -0400
commita71e0af25544fd2486e57ea51c6d05abdbf44c3e (patch)
tree434e8ae22e80ae95c2121a0c89076c7e9388b150 /src/exit
parentca8a4e7fbdeeb05b58ac3d456bae696623b8e312 (diff)
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.
Diffstat (limited to 'src/exit')
1 files changed, 5 insertions, 3 deletions
diff --git a/src/exit/exit.c b/src/exit/exit.c
index 03c46ca5..e4aeaf15 100644
--- a/src/exit/exit.c
+++ b/src/exit/exit.c
@@ -9,9 +9,10 @@ static void dummy()
-/* __towrite.c and atexit.c override these */
+/* __toread.c, __towrite.c, and atexit.c override these */
weak_alias(dummy, __funcs_on_exit);
-weak_alias(dummy, __fflush_on_exit);
+weak_alias(dummy, __flush_on_exit);
+weak_alias(dummy, __seek_on_exit);
void exit(int code)
@@ -23,7 +24,8 @@ void exit(int code)
if (libc.fini) libc.fini();
if (libc.ldso_fini) libc.ldso_fini();
- __fflush_on_exit();
+ __flush_on_exit();
+ __seek_on_exit();