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
This commit is contained in:
Cosimo Cecchi 2024-06-06 16:51:22 +00:00 committed by Allan Jude
parent b5b90ff984
commit 63f5c101a1

View file

@ -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);
}