SETJMP(3)

๐Ÿ“ฆ
version 15.1 ยท 2 versions
, in freebsd 15.1

๐Ÿ’– 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() with siglongjmp() and setjmp() with longjmp() combinations may be used in the same program. But individual calls may not be mixed โ€” for example, the env argument to setjmp() may not be passed to siglongjmp() ๐Ÿ™…โ€โ™€๏ธ
Do not call the longjmp() routines after the routine which called the setjmp() 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. (See sigprocmask(2).)
  • sigsetjmp() / 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

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() 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). Vintage behavior, but make it slay ๐ŸŒˆ


xoxo, Debian ๐Ÿ’– April 2, 2022 ๐ŸŽ€

๐Ÿ“ฆ where this page comes from
  • freebsd 15.1: base 15.1
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms