97295dd0af6d826cb0f5975e6cd5fd728e27fea2
[debian/tar] / gnu / raise.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Provide a non-threads replacement for the POSIX raise function.
4
5    Copyright (C) 2002-2003, 2005-2006, 2009-2013 Free Software Foundation, Inc.
6
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 /* written by Jim Meyering and Bruno Haible */
21
22 #include <config.h>
23
24 /* Specification.  */
25 #include <signal.h>
26
27 #if HAVE_RAISE
28 /* Native Windows platform.  */
29
30 # include <errno.h>
31
32 # include "msvc-inval.h"
33
34 # undef raise
35
36 # if HAVE_MSVC_INVALID_PARAMETER_HANDLER
37 static int
38 raise_nothrow (int sig)
39 {
40   int result;
41
42   TRY_MSVC_INVAL
43     {
44       result = raise (sig);
45     }
46   CATCH_MSVC_INVAL
47     {
48       result = -1;
49       errno = EINVAL;
50     }
51   DONE_MSVC_INVAL;
52
53   return result;
54 }
55 # else
56 #  define raise_nothrow raise
57 # endif
58
59 #else
60 /* An old Unix platform.  */
61
62 # include <unistd.h>
63
64 # define rpl_raise raise
65
66 #endif
67
68 int
69 rpl_raise (int sig)
70 {
71 #if GNULIB_defined_signal_blocking && GNULIB_defined_SIGPIPE
72   if (sig == SIGPIPE)
73     return _gl_raise_SIGPIPE ();
74 #endif
75
76 #if HAVE_RAISE
77   return raise_nothrow (sig);
78 #else
79   return kill (getpid (), sig);
80 #endif
81 }