From 73d372dcc166afc387b4d130ecc00e5dce1fc89a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?=
Date: Mon, 13 Mar 2023 21:26:21 +0000 Subject: tee: avoid undefined behavior after fclose() * iopoll.c (fclose_wait): Rename from confusing fclose_nonblock name. Also adjust to do no operations on the stream after fclose() as this is undefined. Instead use fflush() to determine EAGAIN status. (fwrite_wait): Renamed from confusing fwrite_nonblock name. --- src/tee.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/tee.c') diff --git a/src/tee.c b/src/tee.c index 7785942d6..a1c057816 100644 --- a/src/tee.c +++ b/src/tee.c @@ -314,7 +314,7 @@ tee_files (int nfiles, char **files, bool pipe_check) Standard output is the first one. */ for (i = 0; i <= nfiles; i++) if (descriptors[i] - && ! fwrite_nonblock (buffer, bytes_read, descriptors[i])) + && ! fwrite_wait (buffer, bytes_read, descriptors[i])) { if (fail_output (descriptors, files, i)) ok = false; @@ -332,7 +332,7 @@ tee_files (int nfiles, char **files, bool pipe_check) /* Close the files, but not standard output. */ for (i = 1; i <= nfiles; i++) - if (descriptors[i] && ! fclose_nonblock (descriptors[i])) + if (descriptors[i] && ! fclose_wait (descriptors[i])) { error (0, errno, "%s", quotef (files[i])); ok = false; -- cgit v1.2.1