Blame stdio-common/test-fwrite.c

Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  FILE *f = tmpfile ();
Packit 6c4009
  char obuf[99999], ibuf[sizeof obuf];
Packit 6c4009
  char *line;
Packit 6c4009
  size_t linesz;
Packit 6c4009
Packit 6c4009
  if (! f)
Packit 6c4009
    {
Packit 6c4009
      perror ("tmpfile");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (fputs ("line\n", f) == EOF)
Packit 6c4009
    {
Packit 6c4009
      perror ("fputs");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  memset (obuf, 'z', sizeof obuf);
Packit 6c4009
  memset (ibuf, 'y', sizeof ibuf);
Packit 6c4009
Packit 6c4009
  if (fwrite (obuf, sizeof obuf, 1, f) != 1)
Packit 6c4009
    {
Packit 6c4009
      perror ("fwrite");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  rewind (f);
Packit 6c4009
Packit 6c4009
  line = NULL;
Packit 6c4009
  linesz = 0;
Packit 6c4009
  if (getline (&line, &linesz, f) != 5)
Packit 6c4009
    {
Packit 6c4009
      perror ("getline");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
  if (strcmp (line, "line\n"))
Packit 6c4009
    {
Packit 6c4009
      puts ("Lines differ.  Test FAILED!");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (fread (ibuf, sizeof ibuf, 1, f) != 1)
Packit 6c4009
    {
Packit 6c4009
      perror ("fread");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (memcmp (ibuf, obuf, sizeof ibuf))
Packit 6c4009
    {
Packit 6c4009
      puts ("Buffers differ.  Test FAILED!");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  asprintf (&line, "\
Packit 6c4009
GDB is free software and you are welcome to distribute copies of it\n\
Packit 6c4009
 under certain conditions; type \"show copying\" to see the conditions.\n\
Packit 6c4009
There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
Packit 6c4009
");
Packit 6c4009
Packit 6c4009
  puts ("Test succeeded.");
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
#include "../test-skeleton.c"