sseettjjmmpp() -- General Function (libc)

Save machine state for non-local goto
#iinncclluuddee <sseettjjmmpp.hh>
iinntt sseettjjmmpp(_e_n_v) jjmmpp_bbuuff _e_n_v;

The function call is the only mechanism that C provides to transfer control
between  functions.   This  mechanism,  however,  is  inadequate  for  some
purposes, such as handling  unexpected errors or interrupts at lower levels
of a  program.  To answer  this need, sseettjjmmpp  helps to provide  a non-local
_g_o_t_o facility.   sseettjjmmpp() saves a  stack context in _e_n_v,  and returns value
zero.  The  stack context can be restored with  the function lloonnggjjmmpp(). The
type declaration  for jjmmpp_bbuuff is in the header  file sseettjjmmpp.hh.  The context
saved includes the program counter, stack pointer, and stack frame.

_E_x_a_m_p_l_e
The following gives a simple example of sseettjjmmpp() and lloonnggjjmmpp().

#include <setjmp.h>
#include <stdio.h>

jmp_buf env;    /* place for setjmp to store its environment */

main()
{
    int rc;

    if(rc = setjmp(env)) { /* we come here on return */
        printf("First char was %c\n", rc);
        exit(EXIT_SUCCESS);
    }
    subfun();   /* this never returns */
}

subfun()
{
    char buf[80];

    do {
        printf("Enter some data\n");
        gets(buf);  /* get data */
    } while(!buf[0]);   /* retry on null line */

    longjmp(env, buf[0]);   /* buf[0] must be non zero */
}

_S_e_e _A_l_s_o
ggeetteennvv(), lliibbcc, lloonnggjjmmpp(), ssiiggsseettjjmmpp()
ANSI Standard, section 7.6.1.1
POSIX Standard, section 8.1

_N_o_t_e_s
Programmers should note that many user-level routines cannot be interrupted
and  reentered  safely.  For  that  reason, improper  use  of sseettjjmmpp()  and
lloonnggjjmmpp()  can  create  mysterious and  irreproducible  bugs.   The use  of
lloonnggjjmmpp() to  exit interrupt exception  or signal handlers  is particularly
hazardous.
