raise.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Provide a non-threads replacement for the POSIX raise function.
  2. Copyright (C) 2002-2003, 2005-2006, 2009-2013 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program 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
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /* written by Jim Meyering and Bruno Haible */
  14. #include <config.h>
  15. /* Specification. */
  16. #include <signal.h>
  17. #if HAVE_RAISE
  18. /* Native Windows platform. */
  19. # include <errno.h>
  20. # include "msvc-inval.h"
  21. # undef raise
  22. # if HAVE_MSVC_INVALID_PARAMETER_HANDLER
  23. static int
  24. raise_nothrow (int sig)
  25. {
  26. int result;
  27. TRY_MSVC_INVAL
  28. {
  29. result = raise (sig);
  30. }
  31. CATCH_MSVC_INVAL
  32. {
  33. result = -1;
  34. errno = EINVAL;
  35. }
  36. DONE_MSVC_INVAL;
  37. return result;
  38. }
  39. # else
  40. # define raise_nothrow raise
  41. # endif
  42. #else
  43. /* An old Unix platform. */
  44. # include <unistd.h>
  45. # define rpl_raise raise
  46. #endif
  47. int
  48. rpl_raise (int sig)
  49. {
  50. #if GNULIB_defined_signal_blocking && GNULIB_defined_SIGPIPE
  51. if (sig == SIGPIPE)
  52. return _gl_raise_SIGPIPE ();
  53. #endif
  54. #if HAVE_RAISE
  55. return raise_nothrow (sig);
  56. #else
  57. return kill (getpid (), sig);
  58. #endif
  59. }