setjmp.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Copyright (C) 1991-2026 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, see
  13. <https://www.gnu.org/licenses/>. */
  14. /*
  15. * ISO C99 Standard: 7.13 Nonlocal jumps <setjmp.h>
  16. */
  17. #ifndef _SETJMP_H
  18. #define _SETJMP_H 1
  19. #include <features.h>
  20. __BEGIN_DECLS
  21. #if __GLIBC_USE (ISOC23)
  22. # define __STDC_VERSION_SETJMP_H__ 202311L
  23. #endif
  24. #include <bits/setjmp.h> /* Get `__jmp_buf'. */
  25. #include <bits/types/struct___jmp_buf_tag.h>
  26. typedef struct __jmp_buf_tag jmp_buf[1];
  27. /* Store the calling environment in ENV, also saving the signal mask.
  28. Return 0. */
  29. extern int setjmp (jmp_buf __env) __THROWNL;
  30. /* Store the calling environment in ENV, also saving the
  31. signal mask if SAVEMASK is nonzero. Return 0.
  32. This is the internal name for `sigsetjmp'. */
  33. extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROWNL;
  34. /* Store the calling environment in ENV, not saving the signal mask.
  35. Return 0. */
  36. extern int _setjmp (struct __jmp_buf_tag __env[1]) __THROWNL;
  37. /* Do not save the signal mask. This is equivalent to the `_setjmp'
  38. BSD function. */
  39. #define setjmp(env) _setjmp (env)
  40. /* Jump to the environment saved in ENV, making the
  41. `setjmp' call there return VAL, or 1 if VAL is 0. */
  42. extern void longjmp (struct __jmp_buf_tag __env[1], int __val)
  43. __THROWNL __attribute__ ((__noreturn__));
  44. #if defined __USE_MISC || defined __USE_XOPEN
  45. /* Same. Usually `_longjmp' is used with `_setjmp', which does not save
  46. the signal mask. But it is how ENV was saved that determines whether
  47. `longjmp' restores the mask; `_longjmp' is just an alias. */
  48. extern void _longjmp (struct __jmp_buf_tag __env[1], int __val)
  49. __THROWNL __attribute__ ((__noreturn__));
  50. #endif
  51. #ifdef __USE_POSIX
  52. /* Use the same type for `jmp_buf' and `sigjmp_buf'.
  53. The `__mask_was_saved' flag determines whether
  54. or not `longjmp' will restore the signal mask. */
  55. typedef struct __jmp_buf_tag sigjmp_buf[1];
  56. /* Store the calling environment in ENV, also saving the
  57. signal mask if SAVEMASK is nonzero. Return 0. */
  58. # define sigsetjmp(env, savemask) __sigsetjmp (env, savemask)
  59. /* Jump to the environment saved in ENV, making the
  60. sigsetjmp call there return VAL, or 1 if VAL is 0.
  61. Restore the signal mask if that sigsetjmp call saved it.
  62. This is just an alias `longjmp'. */
  63. extern void siglongjmp (sigjmp_buf __env, int __val)
  64. __THROWNL __attribute__ ((__noreturn__));
  65. #endif /* Use POSIX. */
  66. /* Define helper functions to catch unsafe code. */
  67. #if __USE_FORTIFY_LEVEL > 0
  68. # include <bits/setjmp2.h>
  69. #endif
  70. __END_DECLS
  71. #endif /* setjmp.h */