Blame libio/tst-memstream1.c

Packit 6c4009
#include <mcheck.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
Packit 6c4009
Packit 6c4009
#ifndef CHAR_T
Packit 6c4009
# define CHAR_T char
Packit 6c4009
# define W(o) o
Packit 6c4009
# define OPEN_MEMSTREAM open_memstream
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#define S(s) S1 (s)
Packit 6c4009
#define S1(s) #s
Packit 6c4009
Packit 6c4009
Packit 6c4009
static void
Packit 6c4009
mcheck_abort (enum mcheck_status ev)
Packit 6c4009
{
Packit 6c4009
  printf ("mecheck failed with status %d\n", (int) ev);
Packit 6c4009
  exit (1);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  mcheck_pedantic (mcheck_abort);
Packit 6c4009
Packit 6c4009
  CHAR_T *buf = (CHAR_T *) 1l;
Packit 6c4009
  size_t len = 12345;
Packit 6c4009
  FILE *fp = OPEN_MEMSTREAM (&buf, &len;;
Packit 6c4009
  if (fp == NULL)
Packit 6c4009
    {
Packit 6c4009
      printf ("%s failed\n", S(OPEN_MEMSTREAM));
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (fflush (fp) != 0)
Packit 6c4009
    {
Packit 6c4009
      puts ("fflush failed");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (len != 0)
Packit 6c4009
    {
Packit 6c4009
      puts ("string after no write not empty");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
  if (buf == (CHAR_T *) 1l)
Packit 6c4009
    {
Packit 6c4009
      puts ("buf not updated");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
  if (buf[0] != W('\0'))
Packit 6c4009
    {
Packit 6c4009
      puts ("buf[0] != 0");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  buf = (CHAR_T *) 1l;
Packit 6c4009
  len = 12345;
Packit 6c4009
  if (fclose (fp) != 0)
Packit 6c4009
    {
Packit 6c4009
      puts ("fclose failed");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (len != 0)
Packit 6c4009
    {
Packit 6c4009
      puts ("string after close with no write not empty");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
  if (buf == (CHAR_T *) 1l)
Packit 6c4009
    {
Packit 6c4009
      puts ("buf not updated");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
  if (buf[0] != W('\0'))
Packit 6c4009
    {
Packit 6c4009
      puts ("buf[0] != 0");
Packit 6c4009
      return 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  free (buf);
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
#include "../test-skeleton.c"