SETJMP(3)
๐ SETJMP(3) โ non-local jumps ยท Library Functions Manual
๐ธ NAME
sigsetjmp, siglongjmp, setjmp, longjmp, _setjmp, _longjmp, longjmperror โ non-local jumps
๐ LIBRARY
Standard C Library (libc, -lc). Yes bestie, it lives in libc ๐
โจ 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
Okay so picture a save point in a game, but make it C. The sigsetjmp(), setjmp(), and _setjmp() functions save their calling environment in env. Each one returns 0. Iconic behavior, honestly ๐
The matching longjmp() functions restore the environment saved by their most recent respective invocations of the setjmp() function. Then they return so your program keeps going as if that setjmp() call had just returned the value you passed in val instead of 0. Itโs giving โthe call came back differentโ energy โจ
- Mixing pairs is allowed: both
sigsetjmp()withsiglongjmp()andsetjmp()withlongjmp()combinations may be used in the same program. But individual calls may not be mixed โ for example, theenvargument tosetjmp()may not be passed tosiglongjmp()๐ โโ๏ธ
Do not call thelongjmp()routines after the routine which called thesetjmp()routines returns. Thatโs the cursed timeline, bestie. No cap ๐
All accessible objects have values as of the time the 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 the longjmp() call are indeterminate. So yeah, those values are not giving reliable, and thatโs on purpose ๐ญ
Signal-mask tea โ:
setjmp()/longjmp()pairs save and restore the signal mask._setjmp()/_longjmp()pairs save and restore only the register set and the stack. (Seesigprocmask(2).)sigsetjmp()/siglongjmp()function pairs save and restore the signal mask if the argumentsavemaskis non-zero; otherwise only the register set and the stack are saved.
๐ญ ERRORS
This is the yikes section, so listen up ๐ซถ
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)).
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
๐ STANDARDS
- The
setjmp()andlongjmp()functions conform toISO/IEC 9899:1990(โISO C90โ). - The
sigsetjmp()andsiglongjmp()functions conform toIEEE Std 1003.1-1988(โPOSIX.1โ).
๐ฐ๏ธ HISTORY
The setjmp() and longjmp() functions first appeared in the Programmer's Workbench (PWB/UNIX). Vintage behavior, but make it slay ๐
xoxo, Debian ๐ April 2, 2022 ๐
๐ฆ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 1990, 1991, 1993 The Regents of the University of California. All rights reserved
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms