1 /* ISC license. */
2 
3 #include <skalibs/nonposix.h>
4 #include <errno.h>
5 #include <signal.h>
6 #include <skalibs/sig.h>
7 #include <skalibs/nsig.h>
8 
9 static struct skasigaction skasigstack[SKALIBS_NSIG-1][SIGSTACKSIZE] ;
10 static unsigned int sigsp[SKALIBS_NSIG-1] ;
11 
sig_pusha(int sig,struct skasigaction const * ssa)12 int sig_pusha (int sig, struct skasigaction const *ssa)
13 {
14   if ((sig <= 0) || (sig >= SKALIBS_NSIG)) return (errno = EINVAL, -1) ;
15   if (sigsp[sig-1] >= SIGSTACKSIZE) return (errno = ENOBUFS, -1) ;
16   if (skasigaction(sig, ssa, &skasigstack[sig-1][sigsp[sig-1]]) == -1)
17       return -1 ;
18   return ++sigsp[sig-1] ;
19 }
20 
sig_pop(int sig)21 int sig_pop (int sig)
22 {
23   if ((sig <= 0) || (sig >= SKALIBS_NSIG)) return (errno = EINVAL, -1) ;
24   if (!sigsp[sig-1]) return (errno = EFAULT, -1);
25   if (skasigaction(sig, &skasigstack[sig-1][sigsp[sig-1]-1], 0) == -1)
26     return -1 ;
27   return --sigsp[sig-1] ;
28 }
29