---
name: "_longjmp"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/_longjmp"
---

# \_longjmp(3)

non-local jumps

## NAME

**sigsetjmp**, **siglongjmp**, **setjmp**, **longjmp**, **\_setjmp**, **\_longjmp**, **longjmperror** – non-local jumps

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<setjmp.h\>**

*int*\

**sigsetjmp**(*sigjmp\_buf env*, *int savemask*);

*void*\

**siglongjmp**(*sigjmp\_buf env*, *int val*);

*int*\

**setjmp**(*jmp\_buf env*);

*void*\

**longjmp**(*jmp\_buf env*, *int val*);

*int*\

**\_setjmp**(*jmp\_buf env*);

*void*\

**\_longjmp**(*jmp\_buf env*, *int val*);

*void*\

**longjmperror**(*void*);

## DESCRIPTION

The **sigsetjmp**(), **setjmp**(), and **\_setjmp**() functions save their calling environment in *env*. Each of these functions returns 0.

The corresponding **longjmp**() functions restore the environment saved by their most recent respective invocations of the **setjmp**() function. They then return so that program execution continues as if the corresponding invocation of the **setjmp**() call had just returned the value specified by *val*, instead of 0.

Pairs of calls may be intermixed, i.e., both **sigsetjmp**() and **siglongjmp**() and **setjmp**() and **longjmp**() combinations may be used in the same program, however, individual calls may not, e.g. the *env* argument to **setjmp**() may not be passed to **siglongjmp**().

The **longjmp**() routines may not be called after the routine which called the **setjmp**() routines returns.

All accessible objects have values as of the time **longjmp**() routine was called, except that the values of objects of automatic storage invocation duration that do not have the *volatile* type and have been changed between the **setjmp**() invocation and **longjmp**() call are indeterminate.

The **setjmp**(*Ns*, */*, *Ns*, *Fn*, *longjmp*) pairs save and restore the signal mask while **\_setjmp**(*Ns*, */*, *Ns*, *Fn*, *\_longjmp*) pairs save and restore only the register set and the stack. (See **sigprocmask**(*2*).)

The **sigsetjmp**(*Ns*, */*, *Ns*, *Fn*, *siglongjmp*) function pairs save and restore the signal mask if the argument *savemask* is non-zero, otherwise only the register set and the stack are saved.

## ERRORS

If the contents of the *env* are corrupted, or correspond to an environment that has already returned, the **longjmp**() routine calls the routine **longjmperror**(*3*). If **longjmperror**() returns the program is aborted (see [abort(3)](/abort/3.md)). The default version of **longjmperror**() prints the message “longjmp botch” to standard error and returns. User programs wishing to exit more gracefully should write their own versions of **longjmperror**().

## SEE ALSO

[sigaction(2)](/sigaction/2.md), [sigaltstack(2)](/sigaltstack/2.md), [signal(3)](/signal/3.md)

## STANDARDS

The **setjmp**() and **longjmp**() functions conform to ISO/IEC 9899:1990 (“ISO C90”). The **sigsetjmp**() and **siglongjmp**() functions conform to IEEE Std 1003.1-1988 (“POSIX.1”).

## HISTORY

The **setjmp**() and **longjmp**() functions first appeared in the Programmer's Workbench (PWB/UNIX).
