SETJMP(3-BSD) RISC/os Reference Manual SETJMP(3-BSD)
NAME
setjmp, longjmp - non-local goto
SYNOPSIS
#include <setjmp.h>
setjmp(env)
jmpbuf env;
longjmp(env, val)
jmpbuf env;
setjmp(env)
jmpbuf env;
longjmp(env, val)
jmpbuf env;
DESCRIPTION
These routines are useful for dealing with errors and inter-
rupts encountered in a low-level subroutine of a program.
setjmp saves its stack environment in env for later use by
longjmp. It returns value 0.
longjmp restores the environment saved by the last call of
setjmp. It then returns in such a way that execution con-
tinues as if the call of setjmp had just returned the value
val to the function that invoked setjmp, which must not
itself have returned in the interim. All accessible data
have values as of the time longjmp was called.
setjmp and longjmp save and restore the signal mask sigset-
mask(2), while setjmp and longjmp manipulate only the C
stack and registers.
ERRORS
If the contents of the jmp_buf are corrupted, or correspond
to an environment that has already returned, longjmp calls
the routine longjmperror. If longjmperror returns the pro-
gram is aborted. The default version of longjmperror prints
the message ``longjmp botch'' to standard error and returns.
User programs wishing to exit more gracefully can write
their own versions of longjmperror.
SEE ALSO
sigvec(2), sigstack(2), signal(3)
BUGS
The System V version of longjmp() will turn a return value
of 0 into a 1, whereas the BSD version always returns the
value requested. A number of programs in BSD systems rely
Printed 1/15/91 Page 1
SETJMP(3-BSD) RISC/os Reference Manual SETJMP(3-BSD)
on the current behavior.
Page 2 Printed 1/15/91