LONGJMP(3)                 POSIX Programmer's Manual                LONGJMP(3)



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

NNAAMMEE
       longjmp -- non-local goto

SSYYNNOOPPSSIISS
       #include <setjmp.h>

       void longjmp(jmp_buf _e_n_v, int _v_a_l);

DDEESSCCRRIIPPTTIIOONN
       The functionality described on this reference page is aligned with the
       ISO C standard. Any conflict between the requirements described here
       and the ISO C standard is unintentional. This volume of POSIX.1-2017
       defers to the ISO C standard.

       The _l_o_n_g_j_m_p() function shall restore the environment saved by the most
       recent invocation of _s_e_t_j_m_p() in the same process, with the
       corresponding jjmmpp__bbuuff argument. If the most recent invocation of
       _s_e_t_j_m_p() with the corresponding jjmmpp__bbuuff occurred in another thread, or
       if there is no such invocation, or if the function containing the
       invocation of _s_e_t_j_m_p() has terminated execution in the interim, or if
       the invocation of _s_e_t_j_m_p() was within the scope of an identifier with
       variably modified type and execution has left that scope in the
       interim, the behavior is undefined.  It is unspecified whether
       _l_o_n_g_j_m_p() restores the signal mask, leaves the signal mask unchanged,
       or restores it to its value at the time _s_e_t_j_m_p() was called.

       All accessible objects have values, and all other components of the
       abstract machine have state (for example, floating-point status flags
       and open files), as of the time _l_o_n_g_j_m_p() was called, except that the
       values of objects of automatic storage duration are unspecified if they
       meet all the following conditions:

        *  They are local to the function containing the corresponding
           _s_e_t_j_m_p() invocation.

        *  They do not have volatile-qualified type.

        *  They are changed between the _s_e_t_j_m_p() invocation and _l_o_n_g_j_m_p()
           call.

       Although _l_o_n_g_j_m_p() is an async-signal-safe function, if it is invoked
       from a signal handler which interrupted a non-async-signal-safe
       function or equivalent (such as the processing equivalent to _e_x_i_t()
       performed after a return from the initial call to _m_a_i_n()), the behavior
       of any subsequent call to a non-async-signal-safe function or
       equivalent is undefined.

       The effect of a call to _l_o_n_g_j_m_p() where initialization of the jjmmpp__bbuuff
       structure was not performed in the calling thread is undefined.

RREETTUURRNN VVAALLUUEE
       After _l_o_n_g_j_m_p() is completed, program execution continues as if the
       corresponding invocation of _s_e_t_j_m_p() had just returned the value
       specified by _v_a_l.  The _l_o_n_g_j_m_p() function shall not cause _s_e_t_j_m_p() to
       return 0; if _v_a_l is 0, _s_e_t_j_m_p() shall return 1.

EERRRROORRSS
       No errors are defined.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       Applications whose behavior depends on the value of the signal mask
       should not use _l_o_n_g_j_m_p() and _s_e_t_j_m_p(), since their effect on the signal
       mask is unspecified, but should instead use the _s_i_g_l_o_n_g_j_m_p() and
       _s_i_g_s_e_t_j_m_p() functions (which can save and restore the signal mask under
       application control).

       It is recommended that applications do not call _l_o_n_g_j_m_p() or
       _s_i_g_l_o_n_g_j_m_p() from signal handlers. To avoid undefined behavior when
       calling these functions from a signal handler, the application needs to
       ensure one of the following two things:

        1. After the call to _l_o_n_g_j_m_p() or _s_i_g_l_o_n_g_j_m_p() the process only calls
           async-signal-safe functions and does not return from the initial
           call to _m_a_i_n().

        2. Any signal whose handler calls _l_o_n_g_j_m_p() or _s_i_g_l_o_n_g_j_m_p() is blocked
           during _e_v_e_r_y call to a non-async-signal-safe function, and no such
           calls are made after returning from the initial call to _m_a_i_n().

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _s_e_t_j_m_p(), _s_i_g_a_c_t_i_o_n(), _s_i_g_l_o_n_g_j_m_p(), _s_i_g_s_e_t_j_m_p()

       The Base Definitions volume of POSIX.1-2017, <<sseettjjmmpp..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  In the event of any discrepancy between this version and the
       original IEEE and The Open Group Standard, the original IEEE and The
       Open Group Standard is the referee document. The original Standard can
       be obtained online at http://www.opengroup.org/unix/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                           LONGJMP(3)
