chiark / gitweb /
Merge branch 'master' of git.distorted.org.uk:~mdw/publish/public-git/disorder
[disorder] / lib / signame.c
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder.
5aff007d 3 * Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell
460b9539 4 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
460b9539 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
460b9539 8 * (at your option) any later version.
e7eb3a27
RK
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 *
460b9539 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
460b9539 17 */
132a5a4a
RK
18/** @file lib/signame.c
19 * @brief Signal names
20 */
05b75f8d 21#include "common.h"
460b9539 22
23#include <signal.h>
24#include <stddef.h>
25
26#include "table.h"
27#include "signame.h"
28
2c6ee627 29/** @brief Mapping between signal names and numbers */
460b9539 30static const struct sigtable {
2c6ee627 31 /** @brief Signal number */
460b9539 32 int signal;
2c6ee627
RK
33
34 /* @brief Signal name ("SIGwhatever") */
460b9539 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
132a5a4a
RK
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 */
460b9539 145int find_signal(const char *s) {
146 int n;
147
ba937f01 148 if((n = TABLE_FIND(signals, name, s)) < 0)
460b9539 149 return -1;
150 return signals[n].signal;
151}
152
153/*
154Local Variables:
155c-basic-offset:2
156comment-column:40
157fill-column:79
158indent-tabs-mode:nil
159End:
160*/