1.\" $NetBSD: setjmp.3,v 1.5 1995/02/27 05:50:26 cgd Exp $ 2.\" 3.\" Copyright (c) 1990, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" the American National Standards Committee X3, on Information 8.\" Processing Systems. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 3. All advertising materials mentioning features or use of this software 19.\" must display the following acknowledgement: 20.\" This product includes software developed by the University of 21.\" California, Berkeley and its contributors. 22.\" 4. Neither the name of the University nor the names of its contributors 23.\" may be used to endorse or promote products derived from this software 24.\" without specific prior written permission. 25.\" 26.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36.\" SUCH DAMAGE. 37.\" 38.\" @(#)setjmp.3 8.1 (Berkeley) 6/4/93 39.\" 40.Dd June 4, 1993 41.Dt SETJMP 3 42.Os BSD 4 43.Sh NAME 44.Nm sigsetjmp , 45.Nm siglongjmp , 46.Nm setjmp , 47.Nm longjmp , 48.Nm _setjmp , 49.Nm _longjmp , 50.Nm longjmperror 51.Nd non-local jumps 52.Sh SYNOPSIS 53.Fd #include <setjmp.h> 54.Ft int 55.Fn sigsetjmp "sigjmp_buf env" "int savemask" 56.Ft void 57.Fn siglongjmp "sigjmp_buf env" "int val" 58.Ft int 59.Fn setjmp "jmp_buf env" 60.Ft void 61.Fn longjmp "jmp_buf env" "int val" 62.Ft int 63.Fn _setjmp "jmp_buf env" 64.Ft void 65.Fn _longjmp "jmp_buf env" "int val" 66.Ft void 67.Fn longjmperror void 68.Sh DESCRIPTION 69The 70.Fn sigsetjmp , 71.Fn setjmp , 72and 73.Fn _setjmp 74functions save their calling environment in 75.Fa env . 76Each of these functions returns 0. 77.Pp 78The corresponding 79.Fn longjmp 80functions restore the environment saved by their most recent respective 81invocations 82of the 83.Fn setjmp 84function. 85They then return so that program execution continues as if the corresponding 86invocation of the 87.Fn setjmp 88call had just returned the value specified by 89.Fa val , 90instead of 0. 91.Pp 92Pairs of calls may be intermixed, i.e. both 93.Fn sigsetjmp 94and 95.Fn siglongjmp 96and 97.Fn setjmp 98and 99.Fn longjmp 100combinations may be used in the same program, however, individual 101calls may not, e.g. the 102.Fa env 103argument to 104.Fn setjmp 105may not be passed to 106.Fn siglongjmp . 107.Pp 108The 109.Fn longjmp 110routines may not be called after the routine which called the 111.Fn setjmp 112routines returns. 113.Pp 114All accessible objects have values as of the time 115.Fn longjmp 116routine was called, except that the values of objects of automatic storage 117invocation duration that do not have the 118.Em volatile 119type and have been changed between the 120.Fn setjmp 121invocation and 122.Fn longjmp 123call are indeterminate. 124.Pp 125The 126.Fn setjmp Ns / Ns Fn longjmp 127pairs save and restore the signal mask while 128.Fn _setjmp Ns / Ns Fn _longjmp 129pairs save and restore only the register set and the stack. 130(See 131.Fn sigmask 2 . ) 132.Pp 133The 134.Fn sigsetjmp Ns / Ns Fn siglongjmp 135function 136pairs save and restore the signal mask if the argument 137.Fa savemask 138is non-zero, otherwise only the register set and the stack are saved. 139.Sh ERRORS 140If the contents of the 141.Fa env 142are corrupted, or correspond to an environment that has already returned, 143the 144.Fn longjmp 145routine calls the routine 146.Fn longjmperror 3 . 147If 148.Fn longjmperror 149returns the program is aborted (see 150.Xr abort 2 ) . 151The default version of 152.Fn longjmperror 153prints the message 154.Dq Li longjmp botch 155to standard error and returns. 156User programs wishing to exit more gracefully should write their own 157versions of 158.Fn longjmperror . 159.Sh SEE ALSO 160.Xr sigaction 2 , 161.Xr sigaltstack 2 , 162.Xr signal 3 163.Sh STANDARDS 164The 165.Fn setjmp 166and 167.Fn longjmp 168functions conform to 169.St -ansiC . 170The 171.Fn sigsetjmp 172and 173.Fn siglongjmp 174functions conform to 175.St -p1003.1-90 . 176