wip update - use the fetched mesa gallium paths and files.
[AROS.git] / compiler / stdc / __signal.c
blob0d1772cbb6de6e73ce291f1d8078b2d57cc319ac
1 /*
2 Copyright © 2012-2018, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
8 #define __NOBLIBBASE__
10 #include <libraries/stdc.h>
12 /* We include the signal.h of posixc.library for getting min/max signal number
13 TODO: Implement more elegant way to get maximum and minimum signal number
15 #include <aros/posixc/signal.h>
16 #include <errno.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <assert.h>
21 #include "__stdc_intbase.h"
22 #include "__signal.h"
23 #include "__optionallibs.h"
25 #define DEBUG 0
26 #include <aros/debug.h>
28 struct signal_func_data *__sig_getfuncdata(int signum)
30 struct StdCIntBase *StdCBase =
31 (struct StdCIntBase *)__aros_getbase_StdCBase();
32 int i;
34 if (signum < SIGHUP || signum > _SIGMAX)
36 errno = EINVAL;
37 return NULL;
40 if (StdCBase->sigfunc_array == NULL)
42 StdCBase->sigfunc_array = malloc(_SIGMAX*sizeof(struct signal_func_data));
44 if (!StdCBase->sigfunc_array)
46 errno = ENOMEM;
47 return NULL;
50 for (i = 0; i < _SIGMAX; i++)
52 StdCBase->sigfunc_array[i].sigfunc = SIG_DFL;
53 StdCBase->sigfunc_array[i].flags = 0;
57 return &StdCBase->sigfunc_array[signum-1];
60 /* Handler for SIG_DFL */
61 /* TODO: Maybe a mechanism has to be implemented so that default signal handler
62 can be overloaded by libraries. For example by stdcio.library or posixc.library
63 so they can use stdio for presenting the caught signal
65 void __sig_default(int signum)
67 struct StdCIntBase *StdCBase =
68 (struct StdCIntBase *)__aros_getbase_StdCBase();
69 char *taskname = FindTask(NULL)->tc_Node.ln_Name;
70 char s[50];
72 switch (signum)
74 case SIGABRT:
75 sprintf(s, "Program '%s' aborted.", taskname);
76 break;
78 case SIGTERM:
79 sprintf(s, "Program '%s' terminated.", taskname);
80 break;
82 default:
83 sprintf(s, "Program '%s' caught signal %d\naborting...",
84 taskname, signum
86 break;
89 /* Open requester if IntuitionBase is available otherwise use kprintf() */
90 if (__intuition_available(StdCBase))
92 struct EasyStruct es =
94 sizeof(struct EasyStruct),
96 "Caught Signal",
97 "%s",
98 "OK"
100 stdcEasyRequest(StdCBase->StdCIntuitionBase, NULL, &es, NULL, s);
102 else
103 kprintf("%s\n", s);
105 __stdc_jmp2exit(0, 20);
107 assert(0); /* Should not be reached */