]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/setjmp.3
epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, ioprio_set.2, signalfd.2, spu_c...
[thirdparty/man-pages.git] / man3 / setjmp.3
CommitLineData
fea681da
MK
1.\" Written by Michael Haardt, Fri Nov 25 14:51:42 MET 1994
2.\"
6a8d8745 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.\" "
c07a3ca3 27.TH SETJMP 3 2009-06-26 "" "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
MK
55.BR setjmp ()
56saves the stack context/environment in \fIenv\fP for
57later use by
58.BR longjmp (3).
c13182ef 59The stack context will be invalidated
60a90ecd
MK
60if the function which called
61.BR setjmp ()
62returns.
fea681da 63.P
60a90ecd
MK
64.BR sigsetjmp ()
65is similar to
66.BR setjmp ().
c7094399 67If, and only if, \fIsavesigs\fP is nonzero,
1192ed94
MK
68the process's current signal mask is saved in \fIenv\fP
69and will be restored if a
60a90ecd
MK
70.BR siglongjmp (3)
71is later performed with this \fIenv\fP.
47297adb 72.SH RETURN VALUE
60a90ecd
MK
73.BR setjmp ()
74and
75.BR sigsetjmp ()
76return 0 if returning directly, and
c7094399 77nonzero when returning from
60a90ecd 78.BR longjmp (3)
c07a3ca3
MF
79or
80.BR siglongjmp (3)
60a90ecd 81using the saved context.
47297adb 82.SH CONFORMING TO
60a90ecd
MK
83C89, C99, and POSIX.1-2001 specify
84.BR setjmp ().
85POSIX.1-2001 specifies
86.BR sigsetjmp ().
fea681da 87.SH NOTES
60a90ecd
MK
88POSIX does not specify whether
89.BR setjmp ()
c07a3ca3 90will save the signal mask.
e739a268 91In System V it will not.
c13182ef 92In 4.3BSD it will, and there
e739a268
MK
93is a function \fB_setjmp\fP that will not.
94By default, Linux/glibc follows the System V behavior,
95but the BSD behavior is provided if the
96.BR _BSD_SOURCE
97feature test macro is defined and none of
98.BR _POSIX_SOURCE ,
99.BR _POSIX_C_SOURCE ,
100.BR _XOPEN_SOURCE ,
101.BR _XOPEN_SOURCE_EXTENDED ,
102.BR _GNU_SOURCE ,
103or
104.B _SVID_SOURCE
105is defined.
106
1192ed94
MK
107If you want to portably save and restore signal masks, use
108.BR sigsetjmp ()
109and
0b80cf56 110.BR siglongjmp (3).
fea681da 111.P
60a90ecd
MK
112.BR setjmp ()
113and
114.BR sigsetjmp ()
115make programs hard to understand
c13182ef
MK
116and maintain.
117If possible an alternative should be used.
47297adb 118.SH SEE ALSO
fea681da
MK
119.BR longjmp (3),
120.BR siglongjmp (3)