setjmpのヘルプ・マニュアル
日本語 英語
setjmp --help
man setjmp
SETJMP(3) Linux Programmer’s Manual SETJMP(3)
名前
setjmp, sigsetjmp - 非局所的なジャンプのために、スタックコンテキスト
(stack context) を保存する
書式
#include
int setjmp(jmp_buf env);
int sigsetjmp(sigjmp_buf env, int savesigs);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
setjmp(): 「注意」参照。
sigsetjmp(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_C_SOURCE
説明
setjmp() と longjmp(3) は、プログラムの低レベルなサブルーチンにおいて、
エ ラ ー や 割 り 込 み が 発生した時の処理に便利である。 setjmp() は、
longjmp(3) によって使われる env にスタックコンテキスト/スタック環境を保
存 する。 setjmp() を呼び出した関数が返るときに、そのスタックコンテキス
トは無効になる。
sigsetjmp() も setjmp() と同様である。 savesigs が 0 以外の場合、このプ
ロ セスの現在のシグナルマスクも env に保存され、このシグナルは後で sig-
longjmp(3) がこの env で実行された際に復元される。
返り値
直接返ってくるときは、 setjmp() と sigsetjmp() は 0 を返し、保存した コ
ンテキストを使って longjmp(3) から返ってくるときは 0 以外を返す。
準拠
setjmp() は C89, C99, POSIX.1-2001 で規定されている。 sigsetjmp() は
POSIX.1-2001 で規定されている。
注意
POSIX は、 setjmp() がシグナルマスクを保存すべきかどうかを規定してい な
い。 System V では保存しない。 4.3BSD では保存する; 4.3BSD にはシグナル
コンテキストを保存しない関数 _setjmp も あ る 。 デ フ ォ ル ト で は
、Linux/glibc は System V の振る舞いに従うが、 _BSD_SOURCE 機能検査マク
ロ が 定 義 さ れ 、 _POSIX_SOURCE, _POSIX_C_SOURCE, _XOPEN_SOURCE,
_XOPEN_SOURCE_EXTENDED, _GNU_SOURCE, _SVID_SOURCE のいずれも定義されて
いない時は BSD の振る舞いとなる。
移植性のある形でシグナルマスクを保存お よ び 復 元 し た い の な ら 、
sigsetjmp() と siglongjmp() を使うこと。
setjmp() や sigsetjmp() を使うと、プログラムは理解しづらく、保守しにく
いものになる。別の方法が可能なら、それを使うべきである。
関連項目
longjmp(3), siglongjmp(3)
2009-01-13 SETJMP(3)
SETJMP(3) Linux Programmer’s Manual SETJMP(3)
NAME
setjmp, sigsetjmp - save stack context for non-local goto
SYNOPSIS
#include
int setjmp(jmp_buf env);
int sigsetjmp(sigjmp_buf env, int savesigs);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
setjmp(): see NOTES.
sigsetjmp(): _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_C_SOURCE
DESCRIPTION
setjmp() and longjmp(3) are useful for dealing with errors and inter-
rupts encountered in a low-level subroutine of a program. setjmp()
saves the stack context/environment in env for later use by longjmp(3).
The stack context will be invalidated if the function which called
setjmp() returns.
sigsetjmp() is similar to setjmp(). If, and only if, savesigs is non-
zero, the process’s current signal mask is saved in env and will be
restored if a siglongjmp(3) is later performed with this env.
RETURN VALUE
setjmp() and sigsetjmp() return 0 if returning directly, and non-zero
when returning from longjmp(3) or siglongjmp(3) using the saved con-
text.
CONFORMING TO
C89, C99, and POSIX.1-2001 specify setjmp(). POSIX.1-2001 specifies
sigsetjmp().
NOTES
POSIX does not specify whether setjmp() will save the signal mask. In
System V it will not. In 4.3BSD it will, and there is a function
_setjmp that will not. By default, Linux/glibc follows the System V
behavior, but the BSD behavior is provided if the _BSD_SOURCE feature
test macro is defined and none of _POSIX_SOURCE, _POSIX_C_SOURCE,
_XOPEN_SOURCE, _XOPEN_SOURCE_EXTENDED, _GNU_SOURCE, or _SVID_SOURCE is
defined.
If you want to portably save and restore signal masks, use sigsetjmp()
and siglongjmp().
setjmp() and sigsetjmp() make programs hard to understand and maintain.
If possible an alternative should be used.
SEE ALSO
longjmp(3), siglongjmp(3)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
2009-06-26 SETJMP(3)