signalnumber.c revision 1.2 1 /* $NetBSD: signalnumber.c,v 1.2 2018/01/04 20:57:29 kamil Exp $ */
2
3 /*
4 * Software available to all and sundry without limitations
5 * but without warranty of fitness for any purpose whatever.
6 *
7 * Licensed for any use, including redistribution in source
8 * and binary forms, with or without modifications, subject
9 * the following agreement:
10 *
11 * Licensee agrees to indemnify licensor, and distributor, for
12 * the full amount of any any claim made by the licensee against
13 * the licensor or distributor, for any action that results from
14 * any use or redistribution of this software, plus any costs
15 * incurred by licensor or distributor resulting from that claim.
16 *
17 * This licence must be retained with the software.
18 */
19
20 #include "namespace.h"
21
22 #include <signal.h>
23 #include <string.h>
24
25 /*
26 * signalnumber()
27 *
28 * Converts the signal named "name" to its
29 * signal number.
30 *
31 * "name" can be the signal name with or without
32 * the leading "SIG" prefix, and character comparisons
33 * are done in a case independent manner.
34 * (ie: SIGINT == INT == int == Int == SiGiNt == (etc).)
35 *
36 * Returns:
37 * 0 on error (invalid signal name)
38 * otherwise the signal number that corresponds to "name"
39 */
40
41 int
42 signalnumber(const char *name)
43 {
44 int i;
45
46 if (strncasecmp(name, "sig", 3) == 0)
47 name += 3;
48
49 for (i = 1; i < NSIG; ++i)
50 if (sys_signame[i] != NULL &&
51 strcasecmp(name, sys_signame[i]) == 0)
52 return i;
53 return 0;
54 }
55