Usermode/libc - Makefile update, move stdin/... to .data for R_*_COPY to work
[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         _SysDebug("abort() - %p", __builtin_return_address(0));
45         _exit(-1);
46 }
47
48 // POSIX
49 int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
50 {
51         if( signum < 0 || signum >= NUM_SIGNALS ) {
52                 errno = EINVAL;
53                 return 1;
54         }
55
56         if( oldact )
57                 *oldact = sighandlers[signum];
58         if( act )
59                 sighandlers[signum] = *act;     
60
61         return 0;
62 }
63
64 int sigemptyset(sigset_t *set)
65 {
66         *set = 0;
67         return 0;
68 }
69 int sigfillset(sigset_t *set)
70 {
71         *set = -1;
72         return 0;
73 }

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