On 10/9/24 07:18, Konstantin Belousov wrote:
On Tue, Oct 08, 2024 at 08:40:45PM +0200, Dag-Erling Smørgrav wrote:
Konstantin Belousov <kostik...@gmail.com> writes:
Dag-Erling Smørgrav <d...@freebsd.org> writes:
+ if (fflush(stdout) != 0)
+ err(1, "stdout");
Why is this check needed?
POSIX requires it.
Could you please point me to the requirement?
Seconding the assertion that it's somewhere in there, but it's also just
a reasonable thing to do. The implicit flush at exit of streams in libc
has to ignore errors because it lacks the necessary context to be able
to surface anything, so applications must do it on an individual basis
to appropriately surface, e.g., output truncation issues that are
otherwise hidden (and maybe not obvious) from the caller.
The impression I had from talking to folks about this in the past is
that it's practically expected that applications will flush-and-error at
the end rather than check individual writes so that they can surface
logic/execution errors at a higher priority than stdout errors, but
stdout errors should still prevent a clean exit.
Thanks,
Kyle Evans