]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/setjmp.3
getauxval.3: wfix
[thirdparty/man-pages.git] / man3 / setjmp.3
CommitLineData
fea681da
MK
1.\" Written by Michael Haardt, Fri Nov 25 14:51:42 MET 1994
2.\"
1dd72f9c 3.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
fea681da
MK
4.\" This is free documentation; you can redistribute it and/or
5.\" modify it under the terms of the GNU General Public License as
6.\" published by the Free Software Foundation; either version 2 of
7.\" the License, or (at your option) any later version.
8.\"
9.\" The GNU General Public License's references to "object code"
10.\" and "executables" are to be interpreted as the output of any
11.\" document formatting or typesetting system, including
12.\" intermediate and printed output.
13.\"
14.\" This manual is distributed in the hope that it will be useful,
15.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17.\" GNU General Public License for more details.
18.\"
19.\" You should have received a copy of the GNU General Public
c715f741
MK
20.\" License along with this manual; if not, see
21.\" <http://www.gnu.org/licenses/>.
6a8d8745 22.\" %%%LICENSE_END
fea681da
MK
23.\"
24.\" Added sigsetjmp, Sun Mar 2 22:03:05 EST 1997, jrv@vanzandt.mv.com
25.\" Modifications, Sun Feb 26 14:39:45 1995, faith@cs.unc.edu
26.\" "
460495ca 27.TH SETJMP 3 2015-08-08 "" "Linux Programmer's Manual"
fea681da 28.SH NAME
24b74457 29setjmp, sigsetjmp \- save stack context for nonlocal goto
fea681da 30.SH SYNOPSIS
fea681da
MK
31.B #include <setjmp.h>
32.sp
33.nf
34.BI "int setjmp(jmp_buf " env );
5895e7eb 35
fea681da
MK
36.BI "int sigsetjmp(sigjmp_buf " env ", int " savesigs );
37.fi
cc4615cc
MK
38.sp
39.in -4n
40Feature Test Macro Requirements for glibc (see
41.BR feature_test_macros (7)):
42.in
43.sp
e739a268
MK
44.BR setjmp ():
45see NOTES.
46.br
cc4615cc 47.BR sigsetjmp ():
0f200f07 48_POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _POSIX_C_SOURCE
fea681da 49.SH DESCRIPTION
60a90ecd
MK
50.BR setjmp ()
51and
52.BR longjmp (3)
53are useful for dealing with errors
fea681da 54and interrupts encountered in a low-level subroutine of a program.
60a90ecd 55.BR setjmp ()
c6fa0841
MK
56saves the stack context/environment in
57.I env
58for
60a90ecd
MK
59later use by
60.BR longjmp (3).
c13182ef 61The stack context will be invalidated
60a90ecd
MK
62if the function which called
63.BR setjmp ()
64returns.
fea681da 65.P
60a90ecd
MK
66.BR sigsetjmp ()
67is similar to
68.BR setjmp ().
c6fa0841
MK
69If, and only if,
70.I savesigs
71is nonzero,
72the process's current signal mask is saved in
73.I env
1192ed94 74and will be restored if a
60a90ecd 75.BR siglongjmp (3)
c6fa0841
MK
76is later performed with this
77.IR env .
47297adb 78.SH RETURN VALUE
60a90ecd
MK
79.BR setjmp ()
80and
81.BR sigsetjmp ()
82return 0 if returning directly, and
c7094399 83nonzero when returning from
60a90ecd 84.BR longjmp (3)
c07a3ca3
MF
85or
86.BR siglongjmp (3)
60a90ecd 87using the saved context.
7855ffa4
ZL
88.SH ATTRIBUTES
89For an explanation of the terms used in this section, see
90.BR attributes (7).
91.TS
92allbox;
93lbw21 lb lb
94l l l.
95Interface Attribute Value
96T{
97.BR setjmp (),
98.BR sigsetjmp ()
99T} Thread safety MT-Safe
100.TE
101
47297adb 102.SH CONFORMING TO
55d3f6e3
MK
103.BR setjmp ():
104POSIX.1-2001, POSIX.1-2008, C89, C99.
105
106.BR sigsetjmp ():
107POSIX.1-2001, POSIX.1-2008.
fea681da 108.SH NOTES
60a90ecd
MK
109POSIX does not specify whether
110.BR setjmp ()
dbb73b9a
MK
111will save the signal mask
112(to be later restored during
113.BR longjmp (3)).
e739a268 114In System V it will not.
c13182ef 115In 4.3BSD it will, and there
c6fa0841
MK
116is a function
117.B _setjmp
118that will not.
dbb73b9a 119On Linux with glibc versions before 2.19,
a896b353 120.BR setjmp ()
dbb73b9a 121follows the System V behavior by default,
e739a268
MK
122but the BSD behavior is provided if the
123.BR _BSD_SOURCE
124feature test macro is defined and none of
125.BR _POSIX_SOURCE ,
126.BR _POSIX_C_SOURCE ,
127.BR _XOPEN_SOURCE ,
128.BR _XOPEN_SOURCE_EXTENDED ,
129.BR _GNU_SOURCE ,
130or
131.B _SVID_SOURCE
132is defined.
dbb73b9a
MK
133Since glibc 2.19,
134.IR <setjmp.h>
135exposes only the System V version of
136.BR setjmp ().
137Programs that need the BSD semantics should replace calls to
138.BR setjmp ()
139with calls to
140.BR sigsetjmp ()
141with a nonzero
142.I savesigs
143argument.
e739a268 144
1192ed94
MK
145If you want to portably save and restore signal masks, use
146.BR sigsetjmp ()
147and
0b80cf56 148.BR siglongjmp (3).
fea681da 149.P
60a90ecd
MK
150.BR setjmp ()
151and
152.BR sigsetjmp ()
153make programs hard to understand
c13182ef 154and maintain.
b947a033 155If possible, an alternative should be used.
47297adb 156.SH SEE ALSO
fea681da
MK
157.BR longjmp (3),
158.BR siglongjmp (3)