148352Scael.\" Copyright (c) 1990, 1991 The Regents of the University of California. 242393Sbostic.\" All rights reserved. 320448Smckusick.\" 450309Sbostic.\" This code is derived from software contributed to Berkeley by 550309Sbostic.\" the American National Standards Committee X3, on Information 650309Sbostic.\" Processing Systems. 750309Sbostic.\" 842393Sbostic.\" %sccs.include.redist.man% 920448Smckusick.\" 10*53257Sbostic.\" @(#)setjmp.3 6.9 (Berkeley) 04/23/92 1142393Sbostic.\" 1248352Scael.Dd 1348352Scael.Dt SETJMP 3 1448352Scael.Os BSD 4 1548352Scael.Sh NAME 1648352Scael.Nm sigsetjmp , 1748352Scael.Nm siglongjmp , 1848352Scael.Nm setjmp , 1948352Scael.Nm longjmp , 2048352Scael.Nm _setjmp , 2148352Scael.Nm _longjmp longjmperror 2248352Scael.Nd non-local jumps 2348352Scael.Sh SYNOPSIS 2448352Scael.Fd #include <setjmp.h> 2548352Scael.Ft int 2648352Scael.Fn sigsetjmp "sigjmp_buf env" "int savemask" 2748352Scael.Ft void 2848352Scael.Fn siglongjmp "sigjmp_buf env" "int val" 2948352Scael.Ft int 3048352Scael.Fn setjmp "jmp_buf env" 3148352Scael.Ft void 3248352Scael.Fn longjmp "jmp_buf env" "int val" 3348352Scael.Ft int 3448352Scael.Fn _setjmp "jmp_buf env" 3548352Scael.Ft void 3648352Scael.Fn _longjmp "jmp_buf env" "int val" 3748352Scael.Ft void 3848352Scael.Fn longjmperror void 3948352Scael.Sh DESCRIPTION 4042393SbosticThe 4148352Scael.Fn sigsetjmp , 4248352Scael.Fn setjmp , 4342393Sbosticand 4448352Scael.Fn _setjmp 4542393Sbosticfunctions save their calling environment in 4648352Scael.Fa env . 4742393SbosticEach of these functions returns 0. 4848352Scael.Pp 4950710ScaelThe corresponding 5048352Scael.Fn longjmp 5148352Scaelfunctions restore the environment saved by their most recent respective 5248352Scaelinvocations 5342393Sbosticof the 5448352Scael.Fn setjmp 5542393Sbosticfunction. 5648352ScaelThey then return so that program execution continues as if the corresponding 5748352Scaelinvocation of the 5848352Scael.Fn setjmp 5948352Scaelcall had just returned the value specified by 6048352Scael.Fa val , 6142393Sbosticinstead of 0. 6248352Scael.Pp 6350710ScaelPairs of calls may be intermixed, i.e. both 6448352Scael.Fn sigsetjmp 6542393Sbosticand 6648352Scael.Fn siglongjmp 6742393Sbosticand 6848352Scael.Fn setjmp 6942393Sbosticand 7048352Scael.Fn longjmp 7142393Sbosticcombinations may be used in the same program, however, individual 7250710Scaelcalls may not, i.e. the 7348352Scael.Fa env 7450710Scaelargument to 7548352Scael.Fn sigsetjmp 7642393Sbosticmay not be passed to 7748352Scael.Fn longjmp . 7848352Scael.Pp 7942393SbosticThe 8048352Scael.Fn longjmp 8142393Sbosticroutines may not be called after the routine which called the 8248352Scael.Fn setjmp 8342393Sbosticroutines returns. 8448352Scael.Pp 8548352ScaelAll accessible objects have values as of the time 8648352Scael.Fn longjmp 8748352Scaelroutine was called, except that the values of objects of automatic storage 8848352Scaelinvocation duration that do not have the 8948352Scael.Em volatile 9048352Scaeltype and have been changed between the 9148352Scael.Fn setjmp 9248352Scaelinvocation and 9348352Scael.Fn longjmp 9448352Scaelcall are indeterminate. 9548352Scael.Pp 9648352ScaelThe 9750710Scael.Fn setjmp Ns / Ns Fn longjmp 9848352Scaelpairs save and restore the signal mask while 9950710Scael.Fn _setjmp Ns / Ns Fn _longjmp 10042393Sbosticpairs save and restore only the register set and the stack. 10150710Scael(See 10248352Scael.Fn sigmask 2 . ) 10348352Scael.Pp 10448352ScaelThe 10550710Scael.Fn sigsetjmp Ns / Ns Fn siglongjmp 10648352Scaelfunction 10742393Sbosticpairs save and restore the signal mask if the argument 10848352Scael.Fa savemask 10942393Sbosticis non-zero, otherwise only the register set and the stack are saved. 11048352Scael.Sh ERRORS 11125785SmckusickIf the contents of the 11248352Scael.Fa env 11325785Smckusickare corrupted, or correspond to an environment that has already returned, 11450710Scaelthe 11548352Scael.Fn longjmp 11642393Sbosticroutine calls the routine 11748352Scael.Fn longjmperror 3 . 11825785SmckusickIf 11948352Scael.Fn longjmperror 12048352Scaelreturns the program is aborted (see 12148352Scael.Xr abort 2 ) . 12250710ScaelThe default version of 12348352Scael.Fn longjmperror 12448352Scaelprints the message 12548352Scael.Dq Li longjmp botch 12648352Scaelto standard error and returns. 12742393SbosticUser programs wishing to exit more gracefully should write their own 12850710Scaelversions of 12948352Scael.Fn longjmperror . 13048352Scael.Sh SEE ALSO 13148352Scael.Xr sigaction 2 , 132*53257Sbostic.Xr sigaltstack 2 , 13348352Scael.Xr signal 3 13448376Scael.Sh STANDARDS 13548376ScaelThe 13648376Scael.Fn setjmp 13748376Scaeland 13848376Scael.Fn longjmp 13948376Scaelfunctions conform to 14048376Scael.St -ansiC . 141