setjmp.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Copyright (C) 1991-1999, 2001 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 Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the 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. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. /*
  16. * ISO C99 Standard: 7.13 Nonlocal 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' and that
  29. `__mask_was_saved' follows it. Do not move these members
  30. or add others before it. */
  31. __jmp_buf __jmpbuf; /* Calling environment. */
  32. int __mask_was_saved; /* Saved the signal mask? */
  33. __sigset_t __saved_mask; /* Saved signal mask. */
  34. } jmp_buf[1];
  35. /* Store the calling environment in ENV, also saving the signal mask.
  36. Return 0. */
  37. extern int setjmp (jmp_buf __env) __THROW;
  38. /* Store the calling environment in ENV, not saving the signal mask.
  39. Return 0. */
  40. extern int _setjmp (jmp_buf __env) __THROW;
  41. /* Store the calling environment in ENV, also saving the
  42. signal mask if SAVEMASK is nonzero. Return 0.
  43. This is the internal name for `sigsetjmp'. */
  44. extern int __sigsetjmp (jmp_buf __env, int __savemask) __THROW;
  45. #ifndef __FAVOR_BSD
  46. /* Do not save the signal mask. This is equivalent to the `_setjmp'
  47. BSD function. */
  48. # define setjmp(env) _setjmp (env)
  49. #else
  50. /* We are in 4.3 BSD-compatibility mode in which `setjmp'
  51. saves the signal mask like `sigsetjmp (ENV, 1)'. We have to
  52. define a macro since ISO C says `setjmp' is one. */
  53. # define setjmp(env) setjmp (env)
  54. #endif /* Favor BSD. */
  55. /* Jump to the environment saved in ENV, making the
  56. `setjmp' call there return VAL, or 1 if VAL is 0. */
  57. extern void longjmp (jmp_buf __env, int __val)
  58. __THROW __attribute__ ((__noreturn__));
  59. #if defined __USE_BSD || defined __USE_XOPEN
  60. /* Same. Usually `_longjmp' is used with `_setjmp', which does not save
  61. the signal mask. But it is how ENV was saved that determines whether
  62. `longjmp' restores the mask; `_longjmp' is just an alias. */
  63. extern void _longjmp (jmp_buf __env, int __val)
  64. __THROW __attribute__ ((__noreturn__));
  65. #endif
  66. #ifdef __USE_POSIX
  67. /* Use the same type for `jmp_buf' and `sigjmp_buf'.
  68. The `__mask_was_saved' flag determines whether
  69. or not `longjmp' will restore the signal mask. */
  70. typedef jmp_buf sigjmp_buf;
  71. /* Store the calling environment in ENV, also saving the
  72. signal mask if SAVEMASK is nonzero. Return 0. */
  73. # define sigsetjmp(env, savemask) __sigsetjmp (env, savemask)
  74. /* Jump to the environment saved in ENV, making the
  75. sigsetjmp call there return VAL, or 1 if VAL is 0.
  76. Restore the signal mask if that sigsetjmp call saved it.
  77. This is just an alias `longjmp'. */
  78. extern void siglongjmp (sigjmp_buf __env, int __val)
  79. __THROW __attribute__ ((__noreturn__));
  80. #endif /* Use POSIX. */
  81. __END_DECLS
  82. #endif /* setjmp.h */