Back to index

glibc  2.9
Defines | Functions | Variables
tst-exec.c File Reference
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <wait.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define CMDLINE_OPTIONS   { "restart", no_argument, &restart, 1 },
#define PREPARE   do_prepare

Functions

void do_prepare (int argc, char *argv[])
int do_test (int argc, char *argv[])
static int handle_restart (const char *fd1s, const char *fd2s, const char *name)

Variables

static int restart
static char * name1
static char * name2
static const char fd1string [] = "This file should get closed"
static const char fd2string [] = "This file should stay opened"

Define Documentation

#define CMDLINE_OPTIONS   { "restart", no_argument, &restart, 1 },

Definition at line 34 of file tst-exec.c.

#define PREPARE   do_prepare

Definition at line 42 of file tst-exec.c.


Function Documentation

void do_prepare ( int  argc,
char *  argv[] 
)
int do_test ( int  argc,
char *  argv[] 
)

Definition at line 146 of file test-lfs.c.

{
  int ret;
  struct stat64 statbuf;

  ret = lseek64 (fd, TWO_GB+100, SEEK_SET);
  if (ret == -1 && errno == ENOSYS)
    {
      error (0, 0, "lseek64 is not supported.");
      exit (EXIT_SUCCESS);
    }
  if (ret == -1 && errno == EINVAL)
    {
      error (0, 0, "LFS seems not to be supported.");
      exit (EXIT_SUCCESS);
    }
  if (ret == -1)
    {
      error (0, errno, "lseek64 failed with error");
      exit (EXIT_FAILURE);
    }

  ret = write (fd, "Hello", 5);
  if (ret == -1 && errno == EFBIG)
    {
      error (0, 0, "LFS seems not to be supported.");
      exit (EXIT_SUCCESS);
    }

  if (ret == -1 && errno == ENOSPC)
    {
      error (0, 0, "Not enough space to write file.");
      exit (EXIT_SUCCESS);
    }

  if (ret != 5)
    error (EXIT_FAILURE, errno, "cannot write test string to large file");

  ret = close (fd);

  if (ret == -1)
    error (EXIT_FAILURE, errno, "error closing file");

  ret = stat64 (name, &statbuf);

  if (ret == -1 && (errno == ENOSYS || errno == EOVERFLOW))
    error (0, 0, "stat64 is not supported.");
  else if (ret == -1)
    error (EXIT_FAILURE, errno, "cannot stat file `%s'", name);
  else if (statbuf.st_size != (TWO_GB + 100 + 5))
    error (EXIT_FAILURE, 0, "stat reported size %lld instead of %lld.",
          (long long int) statbuf.st_size, (TWO_GB + 100 + 5));

  test_ftello ();

  return 0;
}
static int handle_restart ( const char *  fd1s,
const char *  fd2s,
const char *  name 
) [static]

Definition at line 76 of file tst-exec.c.

{
  char buf[100];
  int fd1;
  int fd2;

  /* First get the descriptors.  */
  fd1 = atol (fd1s);
  fd2 = atol (fd2s);

  /* Sanity check.  */
  if (fd1 == fd2)
    error (EXIT_FAILURE, 0, "value of fd1 and fd2 is the same");

  /* First the easy part: read from the file descriptor which is
     supposed to be open.  */
  if (lseek (fd2, 0, SEEK_CUR) != strlen (fd2string))
    error (EXIT_FAILURE, errno, "file 2 not in right position");
  if (lseek (fd2, 0, SEEK_SET) != 0)
    error (EXIT_FAILURE, 0, "cannot reset position in file 2");
  if (read (fd2, buf, sizeof buf) != strlen (fd2string))
    error (EXIT_FAILURE, 0, "cannot read file 2");
  if (memcmp (fd2string, buf, strlen (fd2string)) != 0)
    error (EXIT_FAILURE, 0, "file 2 does not match");

  /* No try to read the first file.  First make sure it is not opened.  */
  if (lseek (fd1, 0, SEEK_CUR) != (off_t) -1 || errno != EBADF)
    error (EXIT_FAILURE, 0, "file 1 (%d) is not closed", fd1);

  /* Now open the file and read it.  */
  fd1 = open (name, O_RDONLY);
  if (fd1 == -1)
    error (EXIT_FAILURE, errno,
          "cannot open first file \"%s\" for verification", name);

  if (read (fd1, buf, sizeof buf) != strlen (fd1string))
    error (EXIT_FAILURE, errno, "cannot read file 1");
  if (memcmp (fd1string, buf, strlen (fd1string)) != 0)
    error (EXIT_FAILURE, 0, "file 1 does not match");

  return 0;
}

Here is the call graph for this function:


Variable Documentation

const char fd1string[] = "This file should get closed" [static]

Definition at line 52 of file tst-exec.c.

const char fd2string[] = "This file should stay opened" [static]

Definition at line 53 of file tst-exec.c.

char* name1 [static]

Definition at line 48 of file tst-exec.c.

char* name2 [static]

Definition at line 49 of file tst-exec.c.

int restart [static]

Definition at line 31 of file tst-exec.c.