BSD 4_3_Tahoe release
[unix-history] / usr / src / man / man3 / setjmp.3
CommitLineData
c7eaf808
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
95f51977 5.\" @(#)setjmp.3 6.2 (Berkeley) 1/9/86
c7eaf808 6.\"
95f51977 7.TH SETJMP 3 "January 9, 1986"
c7eaf808
KM
8.UC 4
9.SH NAME
10setjmp, longjmp \- non-local goto
11.SH SYNOPSIS
12.nf
13.B #include <setjmp.h>
14.PP
15.B setjmp(env)
16.B jmp_buf env;
17.PP
18.B longjmp(env, val)
19.B jmp_buf env;
e04f0ee2
KM
20.PP
21.B _setjmp(env)
22.B jmp_buf env;
23.PP
24.B _longjmp(env, val)
25.B jmp_buf env;
c7eaf808
KM
26.fi
27.SH DESCRIPTION
28These routines are useful for dealing with errors
29and interrupts encountered in
30a low-level subroutine of a program.
31.PP
32.I Setjmp
33saves its stack environment in
34.I env
35for later use by
36.I longjmp.
37It returns value 0.
38.PP
39.I Longjmp
40restores the environment saved by the last call of
41.IR setjmp .
42It then returns in such a way that execution
43continues as if the call of
44.I setjmp
45had just returned the value
46.I val
47to the function that invoked
48.I setjmp,
49which must not itself have returned in the interim.
50All accessible data have values as of the time
51.I longjmp
52was called.
e04f0ee2
KM
53.PP
54.I Setjmp
55and
56.I longjmp
57save and restore the signal mask
58.IR sigmask (2),
59while
60.I _setjmp
61and
62.I _longjmp
63manipulate only the C stack and registers.
93a6fb6f
KM
64.SH ERRORS
65.PP
66If the contents of the
67.B jmp_buf
68are corrupted, or correspond to an environment that has already returned,
69.I longjmp
70calls the routine
71.IR longjmperror .
72If
73.I longjmperror
74returns the program is aborted.
75The default version of
76.I longjmperror
77prints the message ``longjmp botch'' to standard error and returns.
78User programs wishing to exit more gracefully can write their own
79versions of
80.IR longjmperror .
c7eaf808 81.SH "SEE ALSO"
e04f0ee2 82sigvec(2), sigstack(2), signal(3)