1SETJMP(3)                  Linux Programmer's Manual                 SETJMP(3)
2
3
4

NAME

6       setjmp, sigsetjmp - save stack context for non-local goto
7

SYNOPSIS

9       #include <setjmp.h>
10
11       int setjmp(jmp_buf env);
12
13       int sigsetjmp(sigjmp_buf env, int savesigs);
14
15   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
16
17       setjmp(): see NOTES.
18       sigsetjmp(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_C_SOURCE
19

DESCRIPTION

21       setjmp()  and  longjmp(3) are useful for dealing with errors and inter‐
22       rupts encountered in a low-level subroutine  of  a  program.   setjmp()
23       saves the stack context/environment in env for later use by longjmp(3).
24       The stack context will be invalidated  if  the  function  which  called
25       setjmp() returns.
26
27       sigsetjmp()  is similar to setjmp().  If, and only if, savesigs is non-
28       zero, the process's current signal mask is saved in  env  and  will  be
29       restored if a siglongjmp(3) is later performed with this env.
30

RETURN VALUE

32       setjmp()  and  sigsetjmp() return 0 if returning directly, and non-zero
33       when returning from longjmp(3) or siglongjmp(3) using  the  saved  con‐
34       text.
35

CONFORMING TO

37       C89,  C99,  and  POSIX.1-2001 specify setjmp().  POSIX.1-2001 specifies
38       sigsetjmp().
39

NOTES

41       POSIX does not specify whether setjmp() will save the signal mask.   In
42       System  V  it  will  not.   In  4.3BSD it will, and there is a function
43       _setjmp that will not.  By default, Linux/glibc follows  the  System  V
44       behavior,  but  the BSD behavior is provided if the _BSD_SOURCE feature
45       test macro is  defined  and  none  of  _POSIX_SOURCE,  _POSIX_C_SOURCE,
46       _XOPEN_SOURCE,  _XOPEN_SOURCE_EXTENDED, _GNU_SOURCE, or _SVID_SOURCE is
47       defined.
48
49       If you want to portably save and restore signal masks, use  sigsetjmp()
50       and siglongjmp().
51
52       setjmp() and sigsetjmp() make programs hard to understand and maintain.
53       If possible an alternative should be used.
54

SEE ALSO

56       longjmp(3), siglongjmp(3)
57

COLOPHON

59       This page is part of release 3.22 of the Linux  man-pages  project.   A
60       description  of  the project, and information about reporting bugs, can
61       be found at http://www.kernel.org/doc/man-pages/.
62
63
64
65                                  2009-06-26                         SETJMP(3)
Impressum