xref: /original-bsd/lib/libc/gen/setjmp.3 (revision 71eaf591)
1.\" Copyright (c) 1990, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the American National Standards Committee X3, on Information
6.\" Processing Systems.
7.\"
8.\" %sccs.include.redist.man%
9.\"
10.\"     @(#)setjmp.3	8.1 (Berkeley) 06/04/93
11.\"
12.Dd
13.Dt SETJMP 3
14.Os BSD 4
15.Sh NAME
16.Nm sigsetjmp ,
17.Nm siglongjmp ,
18.Nm setjmp ,
19.Nm longjmp ,
20.Nm _setjmp ,
21.Nm _longjmp longjmperror
22.Nd non-local jumps
23.Sh SYNOPSIS
24.Fd #include <setjmp.h>
25.Ft int
26.Fn sigsetjmp "sigjmp_buf env" "int savemask"
27.Ft void
28.Fn siglongjmp "sigjmp_buf env" "int val"
29.Ft int
30.Fn setjmp "jmp_buf env"
31.Ft void
32.Fn longjmp "jmp_buf env" "int val"
33.Ft int
34.Fn _setjmp "jmp_buf env"
35.Ft void
36.Fn _longjmp "jmp_buf env" "int val"
37.Ft void
38.Fn longjmperror void
39.Sh DESCRIPTION
40The
41.Fn sigsetjmp ,
42.Fn setjmp ,
43and
44.Fn _setjmp
45functions save their calling environment in
46.Fa env .
47Each of these functions returns 0.
48.Pp
49The corresponding
50.Fn longjmp
51functions restore the environment saved by their most recent respective
52invocations
53of the
54.Fn setjmp
55function.
56They then return so that program execution continues as if the corresponding
57invocation of the
58.Fn setjmp
59call had just returned  the value specified by
60.Fa val ,
61instead of 0.
62.Pp
63Pairs of calls may be intermixed, i.e. both
64.Fn sigsetjmp
65and
66.Fn siglongjmp
67and
68.Fn setjmp
69and
70.Fn longjmp
71combinations may be used in the same program, however, individual
72calls may not, e.g. the
73.Fa env
74argument to
75.Fn setjmp
76may not be passed to
77.Fn siglongjmp .
78.Pp
79The
80.Fn longjmp
81routines may not be called after the routine which called the
82.Fn setjmp
83routines returns.
84.Pp
85All accessible objects have values as of the time
86.Fn longjmp
87routine was called, except that the values of objects of automatic storage
88invocation duration that do not have the
89.Em volatile
90type and have been changed between the
91.Fn setjmp
92invocation and
93.Fn longjmp
94call are indeterminate.
95.Pp
96The
97.Fn setjmp Ns / Ns Fn longjmp
98pairs save and restore the signal mask while
99.Fn _setjmp Ns / Ns Fn _longjmp
100pairs save and restore only the register set and the stack.
101(See
102.Fn sigmask 2 . )
103.Pp
104The
105.Fn sigsetjmp Ns / Ns Fn siglongjmp
106function
107pairs save and restore the signal mask if the argument
108.Fa savemask
109is non-zero, otherwise only the register set and the stack are saved.
110.Sh ERRORS
111If the contents of the
112.Fa env
113are corrupted, or correspond to an environment that has already returned,
114the
115.Fn longjmp
116routine calls the routine
117.Fn longjmperror 3 .
118If
119.Fn longjmperror
120returns the program is aborted (see
121.Xr abort 2 ) .
122The default version of
123.Fn longjmperror
124prints the message
125.Dq Li longjmp botch
126to standard error and returns.
127User programs wishing to exit more gracefully should write their own
128versions of
129.Fn longjmperror .
130.Sh SEE ALSO
131.Xr sigaction 2 ,
132.Xr sigaltstack 2 ,
133.Xr signal 3
134.Sh STANDARDS
135The
136.Fn setjmp
137and
138.Fn longjmp
139functions conform to
140.St -ansiC .
141The
142.Fn sigsetjmp
143and
144.Fn siglongjmp
145functions conform to
146.St -p1003.1-88 .
147