git: 63f5c101a1fd - main - comm: flush stdout for error checking prior to exiting

From: Allan Jude <allanjude_at_FreeBSD.org>
Date: Thu, 06 Jun 2024 17:06:42 UTC
The branch main has been updated by allanjude:

URL: https://cgit.FreeBSD.org/src/commit/?id=63f5c101a1fdf4e8b94c5d76afcd6cbf0b2c79da

commit 63f5c101a1fdf4e8b94c5d76afcd6cbf0b2c79da
Author:     Cosimo Cecchi <cosimo@apple.com>
AuthorDate: 2024-06-06 16:51:22 +0000
Commit:     Allan Jude <allanjude@FreeBSD.org>
CommitDate: 2024-06-06 17:04:37 +0000

    comm: flush stdout for error checking prior to exiting
    
    UNIX conformance wants utilities to catch any errors when doing I/O, as
    opposed to relying on the implicit flush upon exit.
    comm currently does not do that.
    This commit adds handling of I/O errors on stdout prior to exit.
    
    Reviewed by:    imp, allanjude
    Sponsored by:   Apple Inc.
    Differential Revision:  https://reviews.freebsd.org/D45439
---
 usr.bin/comm/comm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/usr.bin/comm/comm.c b/usr.bin/comm/comm.c
index b8fb10ccddb4..2f305e23ce8f 100644
--- a/usr.bin/comm/comm.c
+++ b/usr.bin/comm/comm.c
@@ -172,6 +172,8 @@ main(int argc, char *argv[])
 				(void)printf("%s%s\n", col2, line2);
 		}
 	}
+	if (ferror(stdout) != 0 || fflush(stdout) != 0)
+		err(1, "stdout");
 	exit(0);
 }