Back to index

glibc  2.9
Functions | Variables
tst-setjmp.c File Reference
#include <stdio.h>
#include <setjmp.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

static void jump (int val)
int main (void)

Variables

static jmp_buf env
static int last_value = -1
static int lose = 0

Function Documentation

static void jump ( int  val) [static]

Definition at line 27 of file tst-setjmp.c.

{
  longjmp (env, val);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( void  )

Definition at line 33 of file tst-setjmp.c.

{
  int value;

  value = setjmp (env);
  if (value != last_value + 1)
    {
      fputs("Shouldn't have ", stdout);
      lose = 1;
    }
  last_value = value;
  switch (value)
    {
    case 0:
      puts("Saved environment.");
      jump (0);
    default:
      printf ("Jumped to %d.\n", value);
      if (value < 10)
       jump (value + 1);
    }

  if (!lose && value == 10)
    {
      /* Do a second test, this time without `setjmp' being a macro.
         This is not required by ISO C but we have this for compatibility.  */
#undef setjmp
      extern int setjmp (jmp_buf);

      last_value = -1;
      lose = 0;

      value = setjmp (env);
      if (value != last_value + 1)
       {
         fputs("Shouldn't have ", stdout);
         lose = 1;
       }
      last_value = value;
      switch (value)
       {
       case 0:
         puts("Saved environment.");
         jump (0);
       default:
         printf ("Jumped to %d.\n", value);
         if (value < 10)
           jump (value + 1);
       }
    }

  if (!lose && value == 10)
    {
      /* And again for the `_setjmp' function.  */
#ifndef _setjmp
      extern int _setjmp (jmp_buf);
#endif
      last_value = -1;
      lose = 0;

      value = _setjmp (env);
      if (value != last_value + 1)
       {
         fputs("Shouldn't have ", stdout);
         lose = 1;
       }
      last_value = value;
      switch (value)
       {
       case 0:
         puts("Saved environment.");
         jump (0);
       default:
         printf ("Jumped to %d.\n", value);
         if (value < 10)
           jump (value + 1);
       }
    }

  if (lose || value != 10)
    puts ("Test FAILED!");
  else
    puts ("Test succeeded!");

  return lose ? EXIT_FAILURE : EXIT_SUCCESS;
}

Here is the call graph for this function:


Variable Documentation

jmp_buf env [static]

Definition at line 23 of file tst-setjmp.c.

int last_value = -1 [static]

Definition at line 24 of file tst-setjmp.c.

int lose = 0 [static]

Definition at line 24 of file tst-setjmp.c.