This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/11741] New: printf doesn't return a negative value in case of output error


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.

-- 
           Summary: printf doesn't return a negative value in case of output
                    error
           Product: glibc
           Version: 2.11
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: vincent+libc at vinc17 dot org
                CC: glibc-bugs at sources dot redhat dot com


http://sourceware.org/bugzilla/show_bug.cgi?id=11741

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]