That sounds really tricky. Much simpler is to say: if you care about
the return value of a function, do the function before you call
'exit'. Once you're exiting, don't issue any diagnostics: at that
point your only goal is to exit cleanly. This is the general
strategy
that coreutils uses.
Here's the patch I'm applying. In non-interactive mode, the error
message actually improves - it now tracks the line number of the
m4exit that triggered the detection of the disk full write error.
But in interactive mode, stdout is unbuffered, hence the
write error is detected during the write rather than the fflush,
you've already lost the errno long before. But I don't have any
problems with that [[snip]]