summaryrefslogtreecommitdiff
path: root/src/sysdep.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sysdep.c')
-rw-r--r--src/sysdep.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index 4f89e8aba10..48eebb594f7 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -30,6 +30,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#include <unistd.h>
#include <c-ctype.h>
+#include <close-stream.h>
#include <pathmax.h>
#include <utimens.h>
@@ -2768,6 +2769,25 @@ safe_strsignal (int code)
return signame;
}
+/* Close standard output and standard error, reporting any write
+ errors as best we can. This is intended for use with atexit. */
+void
+close_output_streams (void)
+{
+ if (close_stream (stdout) != 0)
+ {
+ emacs_perror ("Write error to standard output");
+ _exit (EXIT_FAILURE);
+ }
+
+ /* Do not close stderr if addresses are being sanitized, as the
+ sanitizer might report to stderr after this function is invoked. */
+ if (ADDRESS_SANITIZER
+ ? fflush_unlocked (stderr) != 0 || ferror (stderr)
+ : close_stream (stderr) != 0)
+ _exit (EXIT_FAILURE);
+}
+
#ifndef DOS_NT
/* For make-serial-process */
int