xref: /csrg-svn/lib/libc/gen/setjmp.3 (revision 48376)
148352Scael.\" Copyright (c) 1990, 1991 The Regents of the University of California.
242393Sbostic.\" All rights reserved.
320448Smckusick.\"
442393Sbostic.\" %sccs.include.redist.man%
520448Smckusick.\"
6*48376Scael.\"     @(#)setjmp.3	6.6 (Berkeley) 04/20/91
742393Sbostic.\"
848352Scael.Dd
948352Scael.Dt SETJMP 3
1048352Scael.Os BSD 4
1148352Scael.Sh NAME
1248352Scael.Nm sigsetjmp ,
1348352Scael.Nm siglongjmp ,
1448352Scael.Nm setjmp ,
1548352Scael.Nm longjmp ,
1648352Scael.Nm _setjmp ,
1748352Scael.Nm _longjmp longjmperror
1848352Scael.Nd non-local jumps
1948352Scael.Sh SYNOPSIS
2048352Scael.Fd #include <setjmp.h>
2148352Scael.Ft int
2248352Scael.Fn sigsetjmp "sigjmp_buf env" "int savemask"
2348352Scael.Ft void
2448352Scael.Fn siglongjmp "sigjmp_buf env" "int val"
2548352Scael.Ft int
2648352Scael.Fn setjmp "jmp_buf env"
2748352Scael.Ft void
2848352Scael.Fn longjmp "jmp_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 void
3448352Scael.Fn longjmperror void
3548352Scael.Sh DESCRIPTION
3642393SbosticThe
3748352Scael.Fn sigsetjmp ,
3848352Scael.Fn setjmp ,
3942393Sbosticand
4048352Scael.Fn _setjmp
4142393Sbosticfunctions save their calling environment in
4248352Scael.Fa env .
4342393SbosticEach of these functions returns 0.
4448352Scael.Pp
4542393SbosticThe corresponding
4648352Scael.Fn longjmp
4748352Scaelfunctions restore the environment saved by their most recent respective
4848352Scaelinvocations
4942393Sbosticof the
5048352Scael.Fn setjmp
5142393Sbosticfunction.
5248352ScaelThey then return so that program execution continues as if the corresponding
5348352Scaelinvocation of the
5448352Scael.Fn setjmp
5548352Scaelcall had just returned  the value specified by
5648352Scael.Fa val ,
5742393Sbosticinstead of 0.
5848352Scael.Pp
5942393SbosticPairs of calls may be intermixed, i.e. both
6048352Scael.Fn sigsetjmp
6142393Sbosticand
6248352Scael.Fn siglongjmp
6342393Sbosticand
6448352Scael.Fn setjmp
6542393Sbosticand
6648352Scael.Fn longjmp
6742393Sbosticcombinations may be used in the same program, however, individual
6842393Sbosticcalls may not, i.e. the
6948352Scael.Fa env
7042393Sbosticargument to
7148352Scael.Fn sigsetjmp
7242393Sbosticmay not be passed to
7348352Scael.Fn longjmp .
7448352Scael.Pp
7542393SbosticThe
7648352Scael.Fn longjmp
7742393Sbosticroutines may not be called after the routine which called the
7848352Scael.Fn setjmp
7942393Sbosticroutines returns.
8048352Scael.Pp
8148352ScaelAll accessible objects have values as of the time
8248352Scael.Fn longjmp
8348352Scaelroutine was called, except that the values of objects of automatic storage
8448352Scaelinvocation duration that do not have the
8548352Scael.Em volatile
8648352Scaeltype and have been changed between the
8748352Scael.Fn setjmp
8848352Scaelinvocation and
8948352Scael.Fn longjmp
9048352Scaelcall are indeterminate.
9148352Scael.Pp
9248352ScaelThe
9348352Scael.Pa setjmp/longjmp
9448352Scaelpairs save and restore the signal mask while
9548352Scael.Pa _setjmp/_longjmp
9642393Sbosticpairs save and restore only the register set and the stack.
9748352Scael(See
9848352Scael.Fn sigmask 2 . )
9948352Scael.Pp
10048352ScaelThe
10148352Scael.Pa sigsetjmp/siglongjmp
10248352Scaelfunction
10342393Sbosticpairs save and restore the signal mask if the argument
10448352Scael.Fa savemask
10542393Sbosticis non-zero, otherwise only the register set and the stack are saved.
10648352Scael.Sh ERRORS
10725785SmckusickIf the contents of the
10848352Scael.Fa env
10925785Smckusickare corrupted, or correspond to an environment that has already returned,
11042393Sbosticthe
11148352Scael.Fn longjmp
11242393Sbosticroutine calls the routine
11348352Scael.Fn longjmperror 3 .
11425785SmckusickIf
11548352Scael.Fn longjmperror
11648352Scaelreturns the program is aborted (see
11748352Scael.Xr abort 2 ) .
11825785SmckusickThe default version of
11948352Scael.Fn longjmperror
12048352Scaelprints the message
12148352Scael.Dq Li longjmp botch
12248352Scaelto standard error and returns.
12342393SbosticUser programs wishing to exit more gracefully should write their own
12425785Smckusickversions of
12548352Scael.Fn longjmperror .
12648352Scael.Sh SEE ALSO
12748352Scael.Xr sigaction 2 ,
12848352Scael.Xr sigstack 2 ,
12948352Scael.Xr signal 3
130*48376Scael.Sh STANDARDS
131*48376ScaelThe
132*48376Scael.Fn setjmp
133*48376Scaeland
134*48376Scael.Fn longjmp
135*48376Scaelfunctions conform to
136*48376Scael.St -ansiC .
13748352Scael.\" .Sh HISTORY
13848352Scael.\ The
13948352Scael.\ .Nm
14048352Scael.\ function appeared in Version 7 AT&T UNIX.
141