date and time created 93/05/24 10:58:50 by bostic
[unix-history] / usr / src / lib / libc / gen / setjmp.3
CommitLineData
ae59e04c 1.\" Copyright (c) 1990, 1991 The Regents of the University of California.
cc866634 2.\" All rights reserved.
c7eaf808 3.\"
043368e6
KB
4.\" This code is derived from software contributed to Berkeley by
5.\" the American National Standards Committee X3, on Information
6.\" Processing Systems.
7.\"
cc866634
KB
8.\" %sccs.include.redist.man%
9.\"
dc971c33 10.\" @(#)setjmp.3 6.10 (Berkeley) %G%
c7eaf808 11.\"
ae59e04c
CL
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
cc866634 40The
ae59e04c
CL
41.Fn sigsetjmp ,
42.Fn setjmp ,
cc866634 43and
ae59e04c 44.Fn _setjmp
cc866634 45functions save their calling environment in
ae59e04c 46.Fa env .
cc866634 47Each of these functions returns 0.
ae59e04c 48.Pp
bdb37901 49The corresponding
ae59e04c
CL
50.Fn longjmp
51functions restore the environment saved by their most recent respective
52invocations
cc866634 53of the
ae59e04c 54.Fn setjmp
cc866634 55function.
ae59e04c
CL
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 ,
cc866634 61instead of 0.
ae59e04c 62.Pp
bdb37901 63Pairs of calls may be intermixed, i.e. both
ae59e04c 64.Fn sigsetjmp
cc866634 65and
ae59e04c 66.Fn siglongjmp
cc866634 67and
ae59e04c 68.Fn setjmp
cc866634 69and
ae59e04c 70.Fn longjmp
cc866634 71combinations may be used in the same program, however, individual
dc971c33 72calls may not, e.g. the
ae59e04c 73.Fa env
bdb37901 74argument to
dc971c33 75.Fn setjmp
cc866634 76may not be passed to
dc971c33 77.Fn siglongjmp .
ae59e04c 78.Pp
cc866634 79The
ae59e04c 80.Fn longjmp
cc866634 81routines may not be called after the routine which called the
ae59e04c 82.Fn setjmp
cc866634 83routines returns.
ae59e04c
CL
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
bdb37901 97.Fn setjmp Ns / Ns Fn longjmp
ae59e04c 98pairs save and restore the signal mask while
bdb37901 99.Fn _setjmp Ns / Ns Fn _longjmp
cc866634 100pairs save and restore only the register set and the stack.
bdb37901 101(See
ae59e04c
CL
102.Fn sigmask 2 . )
103.Pp
104The
bdb37901 105.Fn sigsetjmp Ns / Ns Fn siglongjmp
ae59e04c 106function
cc866634 107pairs save and restore the signal mask if the argument
ae59e04c 108.Fa savemask
cc866634 109is non-zero, otherwise only the register set and the stack are saved.
ae59e04c 110.Sh ERRORS
93a6fb6f 111If the contents of the
ae59e04c 112.Fa env
93a6fb6f 113are corrupted, or correspond to an environment that has already returned,
bdb37901 114the
ae59e04c 115.Fn longjmp
cc866634 116routine calls the routine
ae59e04c 117.Fn longjmperror 3 .
93a6fb6f 118If
ae59e04c
CL
119.Fn longjmperror
120returns the program is aborted (see
121.Xr abort 2 ) .
bdb37901 122The default version of
ae59e04c
CL
123.Fn longjmperror
124prints the message
125.Dq Li longjmp botch
126to standard error and returns.
cc866634 127User programs wishing to exit more gracefully should write their own
bdb37901 128versions of
ae59e04c
CL
129.Fn longjmperror .
130.Sh SEE ALSO
131.Xr sigaction 2 ,
bce5def7 132.Xr sigaltstack 2 ,
ae59e04c 133.Xr signal 3
d5001484
CL
134.Sh STANDARDS
135The
136.Fn setjmp
137and
138.Fn longjmp
139functions conform to
140.St -ansiC .
dc971c33
KB
141The
142.Fn sigsetjmp
143and
144.Fn siglongjmp
145functions conform to
146.St -p1003.1-88 .