1SETJMP(3)                  Library Functions Manual                  SETJMP(3)
2
3
4

NAME

6       setjmp, longjmp - non-local goto
7

SYNOPSIS

9       #include <setjmp.h>
10
11       setjmp(env)
12       jmp_buf env;
13
14       longjmp(env, val)
15       jmp_buf env;
16
17       _setjmp(env)
18       jmp_buf env;
19
20       _longjmp(env, val)
21       jmp_buf env;
22

DESCRIPTION

24       These  routines  are  useful  for  dealing  with  errors and interrupts
25       encountered in a low-level subroutine of a program.
26
27       Setjmp saves its stack environment in env for later use by longjmp.  It
28       returns value 0.
29
30       Longjmp  restores the environment saved by the last call of setjmp.  It
31       then returns in such a way that execution continues as if the  call  of
32       setjmp  had  just  returned  the value val to the function that invoked
33       setjmp, which must not itself have returned in the interim.  All acces‐
34       sible data have values as of the time longjmp was called.
35
36       Setjmp  and  longjmp save and restore the signal mask sigmask(2), while
37       _setjmp and _longjmp manipulate only the C stack and registers.
38

ERRORS

40       If the contents of the jmp_buf are corrupted, or correspond to an envi‐
41       ronment that has already returned, longjmp calls the routine longjmper‐
42       ror.  If longjmperror returns the program is aborted.  The default ver‐
43       sion  of  longjmperror prints the message ``longjmp botch'' to standard
44       error and returns.  User programs wishing to exit more  gracefully  can
45       write their own versions of longjmperror.
46

SEE ALSO

48       sigvec(2), sigstack(2), signal(3)
49

NOTES (PDP-11)

51       On the PDP-11, longjmperror is called as _ljerr.  This difference stems
52       from the limited name size of the PDP-11  that  requires  all  external
53       names  to  be  unique  within  the  first  seven  characters.  However,
54       <setjmp.h> automatically translates longjmperror to ljerror and  should
55       be included before any definition longjmperror.
56
57       The PDP-11 implementation also contains a subtle bug that occurs when a
58       routine containing a setjmp has register variables.  The bug  sometimes
59       causes  those  variables  to  be given invalid values when a longjmp is
60       made back to the  routine.   Register  variables  should  therefore  be
61       avoided in routines containing setjmps.
62
63       And finally, _longjmp may sometimes die fatally.  Sorry.
64
65
66
674th Berkeley Distribution       January 9, 1986                      SETJMP(3)
Impressum