xref: /netbsd-src/lib/libc/gen/signalnumber.c (revision 796c32c94f6e154afc9de0f63da35c91bb739b45)
1 /* $NetBSD: signalnumber.c,v 1.1 2017/05/09 11:14:16 kre 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 <signal.h>
21 #include <string.h>
22 
23 /*
24  * signalnumber()
25  *
26  *	Converts the signal named "name" to its
27  *	signal number.
28  *
29  *	"name" can be the signal name with or without
30  *	the leading "SIG" prefix, and character comparisons
31  *	are done in a case independent manner.
32  *	(ie: SIGINT == INT == int == Int == SiGiNt == (etc).)
33  *
34  * Returns:
35  *	0 on error (invalid signal name)
36  *	otherwise the signal number that corresponds to "name"
37  */
38 
39 int
40 signalnumber(const char *name)
41 {
42 	int i;
43 
44 	if (strncasecmp(name, "sig", 3) == 0)
45 		name += 3;
46 
47 	for (i = 1; i < NSIG; ++i)
48 		if (sys_signame[i] != NULL &&
49 		    strcasecmp(name, sys_signame[i]) == 0)
50 			return i;
51 	return 0;
52 }
53