Merge branch 'master' of git://cadel.mutabah.net/acess2
[tpg/acess2.git] / Usermode / Libraries / libc.so_src / signals.c
1 /*
2  * AcessOS Basic C Library
3  * signals.c
4 */
5 #include <acess/sys.h>
6 #include <stdlib.h>
7 #include <signal.h>
8 #include "lib.h"
9 #include <errno.h>
10
11 // === CONSTANTS ===
12 #define NUM_SIGNALS     40
13
14 // === GLOBALS ===
15 struct sigaction        sighandlers[NUM_SIGNALS];
16
17 // === CODE ===
18 sighandler_t signal(int num, sighandler_t handler)
19 {
20         sighandler_t    prev;
21         if(num < 0 || num >= NUM_SIGNALS)       return NULL;
22         prev = sighandlers[num].sa_handler;
23         sighandlers[num].sa_handler = handler;
24         sighandlers[num].sa_mask = 0;
25         return prev;
26 }
27
28 int raise(int signal)
29 {
30         if( signal < 0 || signal > NUM_SIGNALS )
31                 return 1;
32         switch(signal)
33         {
34         case SIGABRT:
35                 abort();
36                 break;
37         }
38         return 0;
39 }
40
41 void abort(void)
42 {
43         // raise(SIGABRT);
44         _exit(-1);
45 }
46
47 // POSIX
48 int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
49 {
50         if( signum < 0 || signum >= NUM_SIGNALS ) {
51                 errno = EINVAL;
52                 return 1;
53         }
54
55         if( oldact )
56                 *oldact = sighandlers[signum];
57         if( act )
58                 sighandlers[signum] = *act;     
59
60         return 0;
61 }
62
63 int sigemptyset(sigset_t *set)
64 {
65         *set = 0;
66         return 0;
67 }
68 int sigfillset(sigset_t *set)
69 {
70         *set = -1;
71         return 0;
72 }

UCC git Repository :: git.ucc.asn.au