xref: /csrg-svn/lib/libc/gen/setjmp.3 (revision 50309)
148352Scael.\" Copyright (c) 1990, 1991 The Regents of the University of California.
242393Sbostic.\" All rights reserved.
320448Smckusick.\"
4*50309Sbostic.\" This code is derived from software contributed to Berkeley by
5*50309Sbostic.\" the American National Standards Committee X3, on Information
6*50309Sbostic.\" Processing Systems.
7*50309Sbostic.\"
842393Sbostic.\" %sccs.include.redist.man%
920448Smckusick.\"
10*50309Sbostic.\"     @(#)setjmp.3	6.7 (Berkeley) 06/29/91
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
4942393SbosticThe 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
6342393SbosticPairs 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
7242393Sbosticcalls may not, i.e. the
7348352Scael.Fa env
7442393Sbosticargument 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
9748352Scael.Pa setjmp/longjmp
9848352Scaelpairs save and restore the signal mask while
9948352Scael.Pa _setjmp/_longjmp
10042393Sbosticpairs save and restore only the register set and the stack.
10148352Scael(See
10248352Scael.Fn sigmask 2 . )
10348352Scael.Pp
10448352ScaelThe
10548352Scael.Pa sigsetjmp/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,
11442393Sbosticthe
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 ) .
12225785SmckusickThe 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
12825785Smckusickversions of
12948352Scael.Fn longjmperror .
13048352Scael.Sh SEE ALSO
13148352Scael.Xr sigaction 2 ,
13248352Scael.Xr sigstack 2 ,
13348352Scael.Xr signal 3
13448376Scael.Sh STANDARDS
13548376ScaelThe
13648376Scael.Fn setjmp
13748376Scaeland
13848376Scael.Fn longjmp
13948376Scaelfunctions conform to
14048376Scael.St -ansiC .
14148352Scael.\" .Sh HISTORY
14248352Scael.\ The
14348352Scael.\ .Nm
14448352Scael.\ function appeared in Version 7 AT&T UNIX.
145