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/6719] New: setvbuf set _IOFBF incorrectly


When a file was first open as NON BUFFERED, 
and then we change it into FULL BUFFERED, this will take no effect.

Following code will reproduce this bug.

#include <stdio.h>

int main(void)
{
    if (setvbuf(stderr, NULL, _IOFBF, BUFSIZ) != 0)
        printf("Set full buffer error.\n");

    fprintf(stderr, "Output #1 <stderr>.\n");
    printf("Output #2 <stdout>.\n");

    return 0;
}

If stderr is FULL BUFFERED after setvbuf, then Output #2 will display first.
But we can see Output #1 will display before #2.

And following patch maybe helpful.

--- iosetvbuf-old.c     2003-08-30 03:58:27.000000000 +0800
+++ glibc-2.7/libio/iosetvbuf.c 2008-07-04 15:48:48.000000000 +0800
@@ -45,7 +45,7 @@
   switch (mode)
     {
     case _IOFBF:
-      fp->_IO_file_flags &= ~_IO_LINE_BUF|_IO_UNBUFFERED;
+      fp->_IO_file_flags &= ~(_IO_LINE_BUF|_IO_UNBUFFERED);
       if (buf == NULL)
 	{
 	  if (fp->_IO_buf_base == NULL)

-- 
           Summary: setvbuf set _IOFBF incorrectly
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: wxinee at gmail dot com
                CC: glibc-bugs at sources dot redhat dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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

------- 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]