Home | History | Annotate | Line # | Download | only in gen
      1 /* $NetBSD: signalnext.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 <sys/types.h>
     21 
     22 #include <signal.h>
     23 #include <string.h>
     24 
     25 /*
     26  * signalnext()
     27  *
     28  *	Returns the next signal number after the one given.
     29  *	Giving 0 as 'sig' requests the lowest available signal number.
     30  *
     31  * Returns:
     32  *	-1 on error (invalid 'sig' arg)
     33  *	0  when there is no next.
     34  *	otherwise the next greater implemented signal number after 'sig'
     35  */
     36 
     37 int
     38 signalnext(int sig)
     39 {
     40 
     41 	if (sig < 0 || sig >= NSIG || (sig > 0 && sys_signame[sig] == NULL))
     42 		return -1;
     43 
     44 	while (++sig < NSIG)
     45 		if (sys_signame[sig] != NULL)
     46 			return sig;
     47 
     48 	return 0;
     49 }
     50