gbasys

view src/signal.c @ 3:06726f0b8cd3

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 08 Mar 2012 14:37:17 +0200
parents e3dc7705ad9c
children 72c6429ae953
line source
1 /*
2 Copyright 2004 John Tsiombikas <nuclear@siggraph.org>
4 This file is part of libgba, a library for GameBoy Advance development.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 #include "signal.h"
22 #include "intr.h"
24 static void sig_invalid_handler(int signum) {
25 panic("signal error");
26 }
28 static sighandler_t signal_handler[SIG_MAX];
29 static sighandler_t default_sig_handler[SIG_MAX];
30 static volatile int wait_for_signal;
31 static sighandler_t saved_signal;
33 void sig_init(void) {
34 int i;
36 for(i=0; i<SIG_MAX; i++) {
37 default_sig_handler[i] = sig_invalid_handler;
38 }
40 default_sig_handler[SIGALRM] = SIG_IGN;
41 default_sig_handler[SIGUSR1] = SIG_IGN;
42 default_sig_handler[SIGUSR2] = SIG_IGN;
43 default_sig_handler[SIGIO] = SIG_IGN;
44 default_sig_handler[SIGTTIN] = SIG_IGN;
45 for(i=0; i<SIG_MAX; i++) {
46 signal_handler[i] = default_sig_handler[i];
47 }
48 }
50 sighandler_t signal(int signum, sighandler_t handler) {
51 sighandler_t prev = signal_handler[signum];
53 signal_handler[signum] = handler == SIG_IGN ? 0 : (handler == SIG_DFL ? default_sig_handler[signum] : handler);
55 return prev;
56 }
58 int raise(int signum) {
59 if(signal_handler[signum] != SIG_IGN) {
60 signal_handler[signum](signum);
61 wait_for_signal = 0;
62 }
63 return 0;
64 }
66 int pause(void) {
67 clr_int();
68 wait_for_signal = 1;
69 set_int();
71 while(wait_for_signal);
73 /*errno = EINTR;*/
74 return -1;
75 }
77 void save_signal(int signum) {
78 saved_signal = signal_handler[signum];
79 }
81 void restore_signal(int signum) {
82 signal_handler[signum] = saved_signal;
83 }
85 sighandler_t signal_func(int signum)
86 {
87 return signal_handler[signum];
88 }