# longjmp

## PROLOG



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


## NAME



           longjmp — non-local goto
    


## SYNOPSIS



           #include <setjmp.h>
    
           void longjmp(jmp_buf _env_ , int _val_);
    


## DESCRIPTION



           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 _longjmp_() function shall restore the environment saved by the
           most recent invocation of _setjmp_() in the same process, with the
           corresponding **jmp_buf** argument. If the most recent invocation of
           _setjmp_() with the corresponding **jmp_buf** occurred in another
           thread, or if there is no such invocation, or if the function
           containing the invocation of _setjmp_() has terminated execution in
           the interim, or if the invocation of _setjmp_() 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 _longjmp_() restores the signal mask, leaves the
           signal mask unchanged, or restores it to its value at the time
           _setjmp_() 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 _longjmp_() 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
               _setjmp_() invocation.
    
            *  They do not have volatile-qualified type.
    
            *  They are changed between the _setjmp_() invocation and _longjmp_()
               call.
    
           Although _longjmp_() 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 _exit_() performed after a return from the initial
           call to _main_()), the behavior of any subsequent call to a non-
           async-signal-safe function or equivalent is undefined.
    
           The effect of a call to _longjmp_() where initialization of the
           **jmp_buf** structure was not performed in the calling thread is
           undefined.
    


## RETURN VALUE



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


## ERRORS



           No errors are defined.
    
           _The following sections are informative._
    


## EXAMPLES



           None.
    


## APPLICATION USAGE



           Applications whose behavior depends on the value of the signal
           mask should not use _longjmp_() and _setjmp_(), since their effect on
           the signal mask is unspecified, but should instead use the
           _siglongjmp_() and _sigsetjmp_() functions (which can save and restore
           the signal mask under application control).
    
           It is recommended that applications do not call _longjmp_() or
           _siglongjmp_() 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 _longjmp_() or _siglongjmp_() the process only
               calls async-signal-safe functions and does not return from the
               initial call to _main_().
    
            2. Any signal whose handler calls _longjmp_() or _siglongjmp_() is
               blocked during _every_ call to a non-async-signal-safe function,
               and no such calls are made after returning from the initial
               call to _main_().
    


## RATIONALE



           None.
    


## FUTURE DIRECTIONS



           None.
    


* * *