1 /* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
20 * ANSI Standard: 4.6 NON-LOCAL JUMPS <setjmp.h>
30 /* Get the machine-dependent definition of `__jmp_buf'. */
35 #define __need_sigset_t
38 /* Calling environment, plus possibly a saved signal mask. */
41 __jmp_buf __jmpbuf; /* Calling environment. */
42 int __mask_was_saved; /* Saved the signal mask? */
43 sigset_t __saved_mask; /* Saved signal mask. */
46 /* Store the calling environment in ENV, also saving the
47 signal mask if SAVEMASK is nonzero. Return 0. */
48 extern void __sigjmp_save __P ((sigjmp_buf __env, int __savemask));
50 #define sigsetjmp(env, savemask) \
51 ({ __typeof ((*((sigjmp_buf *) 0))[0]) *__e = (env); \
52 __sigjmp_save (__e, (savemask)); \
53 __setjmp (__e[0].__jmpbuf); })
55 /* Not strictly POSIX-compliant, because it evaluates ENV more than once. */
56 #define sigsetjmp(env, savemask) \
57 (__sigjmp_save ((env), (savemask)), __setjmp ((env)[0].__jmpbuf))
61 /* Jump to the environment saved in ENV, making the
62 sigsetjmp call there return VAL, or 1 if VAL is 0.
63 Restore the signal mask if that sigsetjmp call saved it. */
64 extern __NORETURN void siglongjmp __P ((__const sigjmp_buf __env, int __val));
65 #endif /* Use POSIX. */
70 /* BSD defines `setjmp' and `longjmp' to save and restore the set of
71 blocked signals. For this, `jmp_buf' must be what POSIX calls
72 `sigjmp_buf', which includes that information. */
73 typedef sigjmp_buf jmp_buf;
75 #else /* Don't favor BSD. */
77 /* A `jmp_buf' really is a `jmp_buf'. Oh boy. */
78 typedef __jmp_buf jmp_buf;
80 #endif /* Favor BSD. */
83 /* Jump to the environment saved in ENV, making the
84 setjmp call there return VAL, or 1 if VAL is 0. */
85 extern __NORETURN void __longjmp __P ((__const __jmp_buf __env, int __val));
86 extern __NORETURN void longjmp __P ((__const jmp_buf __env, int __val));
89 #define longjmp(env, val) __longjmp ((env), (val))
90 #endif /* Optimizing. */
92 /* Set ENV to the current position and return 0. */
93 extern int __setjmp __P ((__jmp_buf __env));
94 /* The ANSI C standard says `setjmp' is a macro. */
95 #define setjmp(env) __setjmp (env)
99 extern __NORETURN void _longjmp __P ((__const jmp_buf __env, int __val));
100 #endif /* Use BSD. */
104 /* We are in the mode in which `setjmp' and `longjmp' save and restore
105 the signal mask, and `jmp_buf' is `sigjmp_buf'. */
110 #define setjmp(env) sigsetjmp ((env), 1)
113 #define longjmp(env, val) siglongjmp ((env), (val))
114 #endif /* Optimizing. */
116 #define _setjmp(env) sigsetjmp ((env), 0)
118 #else /* Don't favor BSD. */
120 /* `setjmp' and `_setjmp' are the same. */
121 #define _setjmp(env) setjmp (env)
123 /* `longjmp' and `_longjmp' are the same. */
124 #define _longjmp(env, val) longjmp ((env), (val))
126 #endif /* Favor BSD. */
131 #endif /* setjmp.h */