For fprintf (thus printf), the C standard says: The fprintf function returns the number of characters transmitted, or a negative value if an output or encoding error occurred. But printf doesn't return a negative value in case of output error (at least not in some cases). For instance: #include <stdio.h> int main (void) { int r; r = printf ("%10000s\n", "foo"); fprintf (stderr, "%d\n", r); return 0; } Then I get: $ ./out > /dev/null 10001 $ ./out >&- 8196 The first case is correct (anything can be written to /dev/null), but in the second case (where the fd is closed), there's obviously an output error (the return value is not 10001), but in such a case, r should have been negative. Tested with glibc 2.11.2 on a Debian/unstable machine and on Fedora release 12 machine. This bug looks like bug 1146, but that one was fixed 5 years ago.
Fixed in master: http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=2b766585f9b4ffabeef2f36200c275976b93f2c7