debian/: Add .gitignore
[disorder] / lib / signame.c
1 /*
2 * This file is part of DisOrder.
3 * Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 /** @file lib/signame.c
19 * @brief Signal names
20 */
21 #include "common.h"
22
23 #include <signal.h>
24 #include <stddef.h>
25
26 #include "table.h"
27 #include "signame.h"
28
29 /** @brief Mapping between signal names and numbers */
30 static const struct sigtable {
31 /** @brief Signal number */
32 int signal;
33
34 /* @brief Signal name ("SIGwhatever") */
35 const char *name;
36 } signals[] = {
37 #define S(sig) { sig, #sig }
38 /* table must be kept in lexical order */
39 #ifdef SIGABRT
40 S(SIGABRT),
41 #endif
42 #ifdef SIGALRM
43 S(SIGALRM),
44 #endif
45 #ifdef SIGBUS
46 S(SIGBUS),
47 #endif
48 #ifdef SIGCHLD
49 S(SIGCHLD),
50 #endif
51 #ifdef SIGCONT
52 S(SIGCONT),
53 #endif
54 #ifdef SIGFPE
55 S(SIGFPE),
56 #endif
57 #ifdef SIGHUP
58 S(SIGHUP),
59 #endif
60 #ifdef SIGILL
61 S(SIGILL),
62 #endif
63 #ifdef SIGINT
64 S(SIGINT),
65 #endif
66 #ifdef SIGIO
67 S(SIGIO),
68 #endif
69 #ifdef SIGIOT
70 S(SIGIOT),
71 #endif
72 #ifdef SIGKILL
73 S(SIGKILL),
74 #endif
75 #ifdef SIGPIPE
76 S(SIGPIPE),
77 #endif
78 #ifdef SIGPOLL
79 S(SIGPOLL),
80 #endif
81 #ifdef SIGPROF
82 S(SIGPROF),
83 #endif
84 #ifdef SIGPWR
85 S(SIGPWR),
86 #endif
87 #ifdef SIGQUIT
88 S(SIGQUIT),
89 #endif
90 #ifdef SIGSEGV
91 S(SIGSEGV),
92 #endif
93 #ifdef SIGSTKFLT
94 S(SIGSTKFLT),
95 #endif
96 #ifdef SIGSTOP
97 S(SIGSTOP),
98 #endif
99 #ifdef SIGSYS
100 S(SIGSYS),
101 #endif
102 #ifdef SIGTERM
103 S(SIGTERM),
104 #endif
105 #ifdef SIGTRAP
106 S(SIGTRAP),
107 #endif
108 #ifdef SIGTSTP
109 S(SIGTSTP),
110 #endif
111 #ifdef SIGTTIN
112 S(SIGTTIN),
113 #endif
114 #ifdef SIGTTOU
115 S(SIGTTOU),
116 #endif
117 #ifdef SIGURG
118 S(SIGURG),
119 #endif
120 #ifdef SIGUSR1
121 S(SIGUSR1),
122 #endif
123 #ifdef SIGUSR2
124 S(SIGUSR2),
125 #endif
126 #ifdef SIGVTALRM
127 S(SIGVTALRM),
128 #endif
129 #ifdef SIGWINCH
130 S(SIGWINCH),
131 #endif
132 #ifdef SIGXCPU
133 S(SIGXCPU),
134 #endif
135 #ifdef SIGXFSZ
136 S(SIGXFSZ),
137 #endif
138 #undef S
139 };
140
141 /** @brief Map a signal name to its number
142 * @param s Signal name e.g. "SIGINT"
143 * @return Signal value or -1 if not found
144 */
145 int find_signal(const char *s) {
146 int n;
147
148 if((n = TABLE_FIND(signals, name, s)) < 0)
149 return -1;
150 return signals[n].signal;
151 }
152
153 /*
154 Local Variables:
155 c-basic-offset:2
156 comment-column:40
157 fill-column:79
158 indent-tabs-mode:nil
159 End:
160 */