Back to index

glibc  2.9
Defines | Functions | Variables
tst-rndseek.c File Reference
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define TEST_FUNCTION   do_test ()
#define TIMEOUT   10

Functions

static int do_test (void)
static int fp_test (const char *name, FILE *fp)

Variables

static char fname [] = "/tmp/rndseek.XXXXXX"
static char tempdata [65 *1024]

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 12 of file tst-rndseek.c.

#define TIMEOUT   10

Definition at line 13 of file tst-rndseek.c.


Function Documentation

static int do_test ( void  ) [static]
static int fp_test ( const char *  name,
FILE fp 
) [static]

Definition at line 19 of file tst-rndseek.c.

{
  int result = 0;
  int rounds = 10000;

  do
    {
      int idx = random () % (sizeof (tempdata) - 2);
      char ch1;
      char ch2;

      if (fseek (fp, idx, SEEK_SET) != 0)
       {
         printf ("%s: %d: fseek failed: %m\n", name, rounds);
         result = 1;
         break;
       }

      ch1 = fgetc_unlocked (fp);
      ch2 = tempdata[idx];
      if (ch1 != ch2)
       {
         printf ("%s: %d: character at index %d not what is expected ('%c' vs '%c')\n",
                name, rounds, idx, ch1, ch2);
         result = 1;
         break;
       }

      ch1 = fgetc (fp);
      ch2 = tempdata[idx + 1];
      if (ch1 != ch2)
       {
         printf ("%s: %d: character at index %d not what is expected ('%c' vs '%c')\n",
                name, rounds, idx + 1, ch1, ch2);
         result = 1;
         break;
       }
    }
  while (--rounds > 0);

  fclose (fp);

  return result;
}

Here is the call graph for this function:


Variable Documentation

char fname[] = "/tmp/rndseek.XXXXXX" [static]

Definition at line 7 of file tst-rndseek.c.

char tempdata[65 *1024] [static]

Definition at line 8 of file tst-rndseek.c.