1LONGJMP(3P)                POSIX Programmer's Manual               LONGJMP(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       longjmp — non-local goto
13

SYNOPSIS

15       #include <setjmp.h>
16
17       void longjmp(jmp_buf env, int val);
18

DESCRIPTION

20       The functionality described on this reference page is aligned with  the
21       ISO C  standard.  Any  conflict between the requirements described here
22       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2017
23       defers to the ISO C standard.
24
25       The  longjmp() function shall restore the environment saved by the most
26       recent invocation of setjmp() in the same process, with the correspond‐
27       ing  jmp_buf  argument.  If the most recent invocation of setjmp() with
28       the corresponding jmp_buf occurred in another thread, or if there is no
29       such  invocation,  or  if  the  function  containing  the invocation of
30       setjmp() has terminated execution in the interim, or if the  invocation
31       of  setjmp()  was within the scope of an identifier with variably modi‐
32       fied type and execution has left that scope in the interim, the  behav‐
33       ior  is  undefined.   It  is unspecified whether longjmp() restores the
34       signal mask, leaves the signal mask unchanged, or restores  it  to  its
35       value at the time setjmp() was called.
36
37       All  accessible  objects  have  values, and all other components of the
38       abstract machine have state (for example, floating-point  status  flags
39       and  open  files), as of the time longjmp() was called, except that the
40       values of objects of automatic storage duration are unspecified if they
41       meet all the following conditions:
42
43        *  They  are  local  to  the  function  containing  the  corresponding
44           setjmp() invocation.
45
46        *  They do not have volatile-qualified type.
47
48        *  They are changed between  the  setjmp()  invocation  and  longjmp()
49           call.
50
51       Although  longjmp()  is an async-signal-safe function, if it is invoked
52       from a signal handler which interrupted a  non-async-signal-safe  func‐
53       tion  or  equivalent  (such as the processing equivalent to exit() per‐
54       formed after a return from the initial call to main()), the behavior of
55       any  subsequent  call to a non-async-signal-safe function or equivalent
56       is undefined.
57
58       The effect of a call to longjmp() where initialization of  the  jmp_buf
59       structure was not performed in the calling thread is undefined.
60

RETURN VALUE

62       After  longjmp()  is  completed,  program execution continues as if the
63       corresponding invocation of setjmp() had just returned the value speci‐
64       fied by val.  The longjmp() function shall not cause setjmp() to return
65       0; if val is 0, setjmp() shall return 1.
66

ERRORS

68       No errors are defined.
69
70       The following sections are informative.
71

EXAMPLES

73       None.
74

APPLICATION USAGE

76       Applications whose behavior depends on the value  of  the  signal  mask
77       should not use longjmp() and setjmp(), since their effect on the signal
78       mask is unspecified,  but  should  instead  use  the  siglongjmp()  and
79       sigsetjmp() functions (which can save and restore the signal mask under
80       application control).
81
82       It is recommended that applications  do  not  call  longjmp()  or  sig‐
83       longjmp()  from signal handlers. To avoid undefined behavior when call‐
84       ing these functions from a signal handler,  the  application  needs  to
85       ensure one of the following two things:
86
87        1. After  the call to longjmp() or siglongjmp() the process only calls
88           async-signal-safe functions and does not return  from  the  initial
89           call to main().
90
91        2. Any signal whose handler calls longjmp() or siglongjmp() is blocked
92           during every call to a non-async-signal-safe function, and no  such
93           calls are made after returning from the initial call to main().
94

RATIONALE

96       None.
97

FUTURE DIRECTIONS

99       None.
100

SEE ALSO

102       setjmp(), sigaction(), siglongjmp(), sigsetjmp()
103
104       The Base Definitions volume of POSIX.1‐2017, <setjmp.h>
105
107       Portions  of  this text are reprinted and reproduced in electronic form
108       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
109       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
110       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
111       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
112       event of any discrepancy between this version and the original IEEE and
113       The  Open Group Standard, the original IEEE and The Open Group Standard
114       is the referee document. The original Standard can be  obtained  online
115       at http://www.opengroup.org/unix/online.html .
116
117       Any  typographical  or  formatting  errors that appear in this page are
118       most likely to have been introduced during the conversion of the source
119       files  to  man page format. To report such errors, see https://www.ker
120       nel.org/doc/man-pages/reporting_bugs.html .
121
122
123
124IEEE/The Open Group                  2017                          LONGJMP(3P)
Impressum