Back to index

glibc  2.9
Defines | Functions | Variables
bug-ungetc4.c File Reference
#include <stdio.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define PREPARE(argc, argv)   do_prepare ()
#define TEST_FUNCTION   do_test ()
#define TEST_POS   5

Functions

static void do_prepare (void)
static int do_test (void)
static int do_one_test (int mode)

Variables

static const char pattern [] = "abcdefghijklmnopqrstuvwxyz"
static char * temp_file

Define Documentation

#define PREPARE (   argc,
  argv 
)    do_prepare ()

Definition at line 24 of file bug-ungetc4.c.

#define TEST_FUNCTION   do_test ()

Definition at line 26 of file bug-ungetc4.c.

#define TEST_POS   5

Definition at line 45 of file bug-ungetc4.c.


Function Documentation

static int do_one_test ( int  mode) [static]

Definition at line 48 of file bug-ungetc4.c.

{
  FILE *f = fopen (temp_file, "r");
  if (f == NULL)
    {
      printf ("%d: could not open temporary file: %m\n", mode);
      return 1;
    }

  int i;
  for (i = 0; i < TEST_POS; ++i)
    getc (f);

  fpos_t p;
  if (fgetpos (f, &p) != 0)
    {
      printf ("%d: fgetpos failed: %m\n", mode);
      return 1;
    }

  if (mode)
    {
      if (fseek (f, 0, SEEK_SET) != 0)
        {
          printf ("%d: fseek failed: %m\n", mode);
          return 1;
        }

      for (i = 0; i < TEST_POS - (mode >= 2); ++i)
        getc (f);
    }

  if (mode != 2 && ungetc ('X', f) != 'X')
    {
      printf ("%d: ungetc failed\n", mode);
      return 1;
    }

  if (mode == 3 && getc (f) != 'X')
    {
      printf ("%d: getc after ungetc did not return X\n", mode);
      return 1;
    }

  if (fsetpos (f, &p) != 0)
    {
      printf ("%d: fsetpos failed: %m\n", mode);
      return 1;
    }

  if (getc (f) != pattern[TEST_POS])
    {
      printf ("%d: getc did not return %c\n", mode, pattern[TEST_POS]);
      return 1;
    }

  fclose (f);

  return 0;
}

Here is the call graph for this function:

static void do_prepare ( void  ) [static]

Definition at line 33 of file bug-ungetc4.c.

{
  int fd = create_temp_file ("bug-ungetc.", &temp_file);
  if (fd == -1)
    {
      printf ("cannot create temporary file: %m\n");
      exit (1);
    }
  write (fd, pattern, sizeof (pattern) - 1);
  close (fd);
}

Here is the call graph for this function:

static int do_test ( void  ) [static]

Variable Documentation

const char pattern[] = "abcdefghijklmnopqrstuvwxyz" [static]

Definition at line 29 of file bug-ungetc4.c.

char* temp_file [static]

Definition at line 30 of file bug-ungetc4.c.