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