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