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)
Fixed in cvs.