1 /* Copyright (C) 1991, 1992 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>
32 /* The `volatile' keyword tells GCC that a function never returns. */
33 #define __NORETURN __volatile
37 #endif /* __NORETURN not defined. */
40 /* Get the machine-dependent definition of `__jmp_buf'. */
45 #define __need_sigset_t
48 /* Calling environment, plus possibly a saved signal mask. */
51 __jmp_buf __jmpbuf; /* Calling environment. */
52 int __mask_was_saved; /* Saved the signal mask? */
53 sigset_t __saved_mask; /* Saved signal mask. */
56 /* Store the calling environment in ENV, also saving the
57 signal mask if SAVEMASK is nonzero. Return 0. */
58 extern void __sigjmp_save __P ((sigjmp_buf __env, int __savemask));
60 #define sigsetjmp(env, savemask) \
61 ({ __typeof ((*((sigjmp_buf *) 0))[0]) *__e = (env); \
62 __sigjmp_save (__e, (savemask)); \
63 __setjmp (__e[0].__jmpbuf); })
65 /* Not strictly POSIX-compliant, because it evaluates ENV more than once. */
66 #define sigsetjmp(env, savemask) \
67 (__sigjmp_save ((env), (savemask)), __setjmp ((env)[0].__jmpbuf))
71 /* Jump to the environment saved in ENV, making the
72 sigsetjmp call there return VAL, or 1 if VAL is 0.
73 Restore the signal mask if that sigsetjmp call saved it. */
74 extern __NORETURN void siglongjmp __P ((__const sigjmp_buf __env, int __val));
75 #endif /* Use POSIX. */
80 /* BSD defines `setjmp' and `longjmp' to save and restore the set of
81 blocked signals. For this, `jmp_buf' must be what POSIX calls
82 `sigjmp_buf', which includes that information. */
83 typedef sigjmp_buf jmp_buf;
85 #else /* Don't favor BSD. */
87 /* A `jmp_buf' really is a `jmp_buf'. Oh boy. */
88 typedef __jmp_buf jmp_buf;
90 #endif /* Favor BSD. */
93 /* Jump to the environment saved in ENV, making the
94 setjmp call there return VAL, or 1 if VAL is 0. */
95 extern __NORETURN void __longjmp __P ((__const __jmp_buf __env, int __val));
96 extern __NORETURN void longjmp __P ((__const jmp_buf __env, int __val));
99 #define longjmp(env, val) __longjmp ((env), (val))
100 #endif /* Optimizing. */
102 /* Set ENV to the current position and return 0. */
103 extern int __setjmp __P ((__jmp_buf __env));
104 /* The ANSI C standard says `setjmp' is a macro. */
105 #define setjmp(env) __setjmp (env)
109 extern __NORETURN void _longjmp __P ((__const jmp_buf __env, int __val));
110 #endif /* Use BSD. */
114 /* We are in the mode in which `setjmp' and `longjmp' save and restore
115 the signal mask, and `jmp_buf' is `sigjmp_buf'. */
120 #define setjmp(env) sigsetjmp ((env), 1)
123 #define longjmp(env, val) siglongjmp ((env), (val))
124 #endif /* Optimizing. */
126 #define _setjmp(env) sigsetjmp ((env), 0)
128 #else /* Don't favor BSD. */
130 /* `setjmp' and `_setjmp' are the same. */
131 #define _setjmp(env) setjmp (env)
133 #endif /* Favor BSD. */
138 #endif /* setjmp.h */