Merge pull request #41 from pder/stdio-flush-on-exit
Flush stdio buffers on exit
This commit is contained in:
commit
574cba3bcb
|
@ -0,0 +1,64 @@
|
|||
SPDX-FileCopyrightText: 2021 Paul Dersey <pdersey@gmail.com>
|
||||
|
||||
SPDX-License-Identifier: MIT
|
||||
|
||||
Make sure real __stdio_exit() is called on exit and not the dummy
|
||||
noop versions. This fixes the issue of truncated output when redirecting
|
||||
output to a file or pipe. It also fixes truncated output on programs
|
||||
that forget to call fclose()
|
||||
diff --git a/src/exit/exit.c b/src/exit/exit.c
|
||||
index a6869b37..a4164682 100644
|
||||
--- src/exit/exit.c
|
||||
+++ src/exit/exit.c
|
||||
@@ -2,16 +2,6 @@
|
||||
#include <stdint.h>
|
||||
#include "libc.h"
|
||||
|
||||
-static void dummy()
|
||||
-{
|
||||
-}
|
||||
-
|
||||
-/* atexit.c and __stdio_exit.c override these. the latter is linked
|
||||
- * as a consequence of linking either __toread.c or __towrite.c. */
|
||||
-weak_alias(dummy, __funcs_on_exit);
|
||||
-weak_alias(dummy, __stdio_exit);
|
||||
-weak_alias(dummy, _fini);
|
||||
-
|
||||
extern weak hidden void (*const __fini_array_start)(void), (*const __fini_array_end)(void);
|
||||
|
||||
static void libc_exit_fini(void)
|
||||
diff --git a/src/internal/stdio_impl.h b/src/internal/stdio_impl.h
|
||||
index d7398f59..69141813 100644
|
||||
--- src/internal/stdio_impl.h
|
||||
+++ src/internal/stdio_impl.h
|
||||
@@ -47,9 +47,9 @@ struct _IO_FILE {
|
||||
struct __locale_struct *locale;
|
||||
};
|
||||
|
||||
-extern hidden FILE *volatile __stdin_used;
|
||||
-extern hidden FILE *volatile __stdout_used;
|
||||
-extern hidden FILE *volatile __stderr_used;
|
||||
+extern FILE *volatile __stdin_used;
|
||||
+extern FILE *volatile __stdout_used;
|
||||
+extern FILE *volatile __stderr_used;
|
||||
|
||||
hidden int __lockfile(FILE *);
|
||||
hidden void __unlockfile(FILE *);
|
||||
diff --git a/src/stdio/__stdio_exit.c b/src/stdio/__stdio_exit.c
|
||||
index a5e42c67..5947a141 100644
|
||||
--- src/stdio/__stdio_exit.c
|
||||
+++ src/stdio/__stdio_exit.c
|
||||
@@ -1,10 +1,5 @@
|
||||
#include "stdio_impl.h"
|
||||
|
||||
-static FILE *volatile dummy_file = 0;
|
||||
-weak_alias(dummy_file, __stdin_used);
|
||||
-weak_alias(dummy_file, __stdout_used);
|
||||
-weak_alias(dummy_file, __stderr_used);
|
||||
-
|
||||
static void close_file(FILE *f)
|
||||
{
|
||||
if (!f) return;
|
||||
--
|
||||
2.30.0
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
SPDX-FileCopyrightText: 2021 Paul Dersey <pdersey@gmail.com>
|
||||
|
||||
SPDX-License-Identifier: MIT
|
||||
|
||||
Force writing to stdout to use line buffering. Works around problem
|
||||
with pipes and redirecting stdout.
|
||||
|
||||
--- src/stdio/__stdout_write.c
|
||||
+++ src/stdio/__stdout_write.c
|
||||
@@ -5,7 +5,6 @@ size_t __stdout_write(FILE *f, const unsigned char *buf, size_t len)
|
||||
{
|
||||
struct winsize wsz;
|
||||
f->write = __stdio_write;
|
||||
- if (!(f->flags & F_SVB) && __syscall(SYS_ioctl, f->fd, TIOCGWINSZ, &wsz))
|
||||
- f->lbf = -1;
|
||||
+ f->lbf = '\n';
|
||||
return __stdio_write(f, buf, len);
|
||||
}
|
||||
--
|
||||
2.30.0
|
||||
|
Loading…
Reference in New Issue