[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GNU hello doesn't not detect write failure

From: Jim Meyering
Subject: GNU hello doesn't not detect write failure
Date: Sun, 07 Nov 2004 19:01:10 +0100

Every (robust) program that writes to standard output must
close stdout just before exiting, *and* report any failure.
GNU hello doesn't do that:

  $ ./hello > /dev/full && echo mistakenly exits successfully
  mistakenly exits successfully

  $ strace -e write ./hello > /dev/full
  write(1, "Hello, world!\n", 14)         = -1 ENOSPC (No space left on device)

I suggest that you add a line near the beginning of main like this:

  atexit (close_stdout);

and use gnulib's `closeout' module.

Note that it's not enough to close stdout at the end of main,
since there are separate exit calls for --help and --version, and
`./hello --help > /dev/full' should also fail.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]