|   | 
| 
 | 
Message-ID: <7858846.L60ANvILD4@linuix>
Date: Sun, 17 Jun 2012 21:26:44 +0200
From: Bruno Haible <bruno@...sp.org>
To: Rich Felker <dalias@...ifal.cx>, musl@...ts.openwall.com
Subject: setvbuf, __fbufsize bug
With musl-0.9.1: This program shows that after calling setvbuf to make
a stream buffered, it may in fact be unbuffered (__fbufsize returns 0).
This problems leads to a unit test failure in gnulib.
============================= foo.c =============================
#include <stdio.h>
#include <stdio_ext.h>
#include <stdlib.h>
#define TESTFILE "t-fbufmode.tmp"
int
main ()
{
  FILE *fp;
  char buf[5];
  /* Create a file with some contents.  */
  fp = fopen (TESTFILE, "w");
  if (fp == NULL)
    goto skip;
  if (fwrite ("foobarsh", 1, 8, fp) < 8)
    goto skip;
  if (fclose (fp))
    goto skip;
  /* Open it for reading.  */
  fp = fopen (TESTFILE, "r");
  if (setvbuf (fp, NULL, _IONBF, 0))
    goto skip;
  if (__fbufsize (fp) > 0)
    {
      fprintf (stderr, "in unbuffered mode, __fbufsize returns > 0 !\n");
      exit (1);
    }
  if (setvbuf (fp, buf, _IOFBF, 5) == 0)
    {
      if (__fbufsize (fp) == 0)
        {
          fprintf (stderr, "in buffered mode, __fbufsize returns 0 !\n");
          exit (1);
        }
    }
  fclose (fp);
  return 0;
 skip:
  fprintf (stderr, "Skipping test: file operations failed.\n");
  return 77;
}
======================================================================
$ musl-gcc foo.c -Wall
$ ./a.out
in buffered mode, __fbufsize returns 0 !
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.