setjmp.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* Copyright (C) 1991,92,93,94,95,96,97,98 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. /*
  16. * ISO C Standard: 4.6 NON-LOCAL JUMPS <setjmp.h>
  17. */
  18. #ifndef _SETJMP_H
  19. #define _SETJMP_H 1
  20. #include <features.h>
  21. __BEGIN_DECLS
  22. #include <bits/setjmp.h> /* Get `__jmp_buf'. */
  23. #include <bits/sigset.h> /* Get `__sigset_t'. */
  24. /* Calling environment, plus possibly a saved signal mask. */
  25. typedef struct __jmp_buf_tag /* C++ doesn't like tagless structs. */
  26. {
  27. /* NOTE: The machine-dependent definitions of `__sigsetjmp'
  28. assume that a `jmp_buf' begins with a `__jmp_buf'.
  29. Do not move this member or add others before it. */
  30. __jmp_buf __jmpbuf; /* Calling environment. */
  31. int __mask_was_saved; /* Saved the signal mask? */
  32. __sigset_t __saved_mask; /* Saved signal mask. */
  33. } jmp_buf[1];
  34. /* Store the calling environment in ENV, also saving the
  35. signal mask if SAVEMASK is nonzero. Return 0.
  36. This is the internal name for `sigsetjmp'. */
  37. extern int __sigsetjmp __P ((jmp_buf __env, int __savemask));
  38. #ifndef __FAVOR_BSD
  39. /* Set ENV to the current position and return 0, not saving the signal mask.
  40. This is just like `sigsetjmp (ENV, 0)'.
  41. The ISO C standard says `setjmp' is a macro. */
  42. # define setjmp(env) __sigsetjmp ((env), 0)
  43. #else
  44. /* We are in 4.3 BSD-compatibility mode in which `setjmp'
  45. saves the signal mask like `sigsetjmp (ENV, 1)'. */
  46. # define setjmp(env) __sigsetjmp ((env), 1)
  47. #endif /* Favor BSD. */
  48. #if defined __USE_BSD || defined __USE_XOPEN
  49. /* Set ENV to the current position and return 0, not saving the signal mask.
  50. This is the 4.3 BSD name for ISO `setjmp'. */
  51. # define _setjmp(env) __sigsetjmp ((env), 0)
  52. #endif
  53. /* Jump to the environment saved in ENV, making the
  54. `setjmp' call there return VAL, or 1 if VAL is 0. */
  55. extern void longjmp __P ((jmp_buf __env, int __val))
  56. __attribute__ ((__noreturn__));
  57. #if defined __USE_BSD || defined __USE_XOPEN
  58. /* Same. Usually `_longjmp' is used with `_setjmp', which does not save
  59. the signal mask. But it is how ENV was saved that determines whether
  60. `longjmp' restores the mask; `_longjmp' is just an alias. */
  61. extern void _longjmp __P ((jmp_buf __env, int __val))
  62. __attribute__ ((__noreturn__));
  63. #endif
  64. /* Use the same type for `jmp_buf' and `sigjmp_buf'.
  65. The `__mask_was_saved' flag determines whether
  66. or not `longjmp' will restore the signal mask. */
  67. typedef jmp_buf sigjmp_buf;
  68. /* Store the calling environment in ENV, also saving the
  69. signal mask if SAVEMASK is nonzero. Return 0. */
  70. # define sigsetjmp(env, savemask) __sigsetjmp ((env), (savemask))
  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. This is just an alias `longjmp'. */
  75. extern void siglongjmp __P ((sigjmp_buf __env, int __val))
  76. __attribute__ ((__noreturn__));
  77. __END_DECLS
  78. #endif /* setjmp.h */