Blame stdio-common/bug5.c

Packit 6c4009
/* If stdio is working correctly, after this is run infile and outfile
Packit 6c4009
   will have the same contents.  If the bug (found in GNU C library 0.3)
Packit 6c4009
   exhibits itself, outfile will be missing the 2nd through 1023rd
Packit 6c4009
   characters.  */
Packit 6c4009
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
Packit 6c4009
static char buf[8192];
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
main (void)
Packit 6c4009
{
Packit 6c4009
  FILE *in;
Packit 6c4009
  FILE *out;
Packit 6c4009
  static char inname[] = OBJPFX "bug5test.in";
Packit 6c4009
  static char outname[] = OBJPFX "bug5test.out";
Packit 6c4009
  char *printbuf;
Packit 6c4009
  size_t i;
Packit 6c4009
  int result;
Packit 6c4009
Packit 6c4009
  /* Create a test file.  */
Packit 6c4009
  in = fopen (inname, "w+");
Packit 6c4009
  if (in == NULL)
Packit 6c4009
    {
Packit 6c4009
      perror (inname);
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
  for (i = 0; i < 1000; ++i)
Packit 6c4009
    fprintf (in, "%Zu\n", i);
Packit 6c4009
Packit 6c4009
  out = fopen (outname, "w");
Packit 6c4009
  if (out == NULL)
Packit 6c4009
    {
Packit 6c4009
      perror (outname);
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
  if (fseek (in, 0L, SEEK_SET) != 0)
Packit 6c4009
    abort ();
Packit 6c4009
  putc (getc (in), out);
Packit 6c4009
  i = fread (buf, 1, sizeof (buf), in);
Packit 6c4009
  if (i == 0)
Packit 6c4009
    {
Packit 6c4009
      perror ("fread");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
  if (fwrite (buf, 1, i, out) != i)
Packit 6c4009
    {
Packit 6c4009
      perror ("fwrite");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
  fclose (in);
Packit 6c4009
  fclose (out);
Packit 6c4009
Packit 6c4009
  puts ("There should be no further output from this test.");
Packit 6c4009
  fflush (stdout);
Packit 6c4009
Packit 6c4009
  /* We must remove this entry to assure the `cmp' binary does not use
Packit 6c4009
     the perhaps incompatible new shared libraries.  */
Packit 6c4009
  unsetenv ("LD_LIBRARY_PATH");
Packit 6c4009
Packit 6c4009
  asprintf (&printbuf, "cmp %s %s", inname, outname);
Packit 6c4009
  result = system (printbuf);
Packit 6c4009
  remove (inname);
Packit 6c4009
  remove (outname);
Packit 6c4009
Packit 6c4009
  exit ((result != 0));
Packit 6c4009
}