Crackle-free audio playback.
[SDL.s60v3.git] / src / SDL_fatal.c
blob784836b9fab0cb0c7e39a7128e8a1ca9600f5d2b
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 Sam Lantinga
20 slouken@libsdl.org
22 #include "SDL_config.h"
24 /* General fatal signal handling code for SDL */
26 #ifdef HAVE_SIGNAL_H
28 #include <signal.h>
30 #include "SDL.h"
31 #include "SDL_fatal.h"
33 /* This installs some signal handlers for the more common fatal signals,
34 so that if the programmer is lazy, the app doesn't die so horribly if
35 the program crashes.
38 static void SDL_Parachute(int sig)
40 signal(sig, SIG_DFL);
41 SDL_Quit();
42 raise(sig);
45 static int SDL_fatal_signals[] = {
46 SIGSEGV,
47 #ifdef SIGBUS
48 SIGBUS,
49 #endif
50 #ifdef SIGFPE
51 SIGFPE,
52 #endif
53 #ifdef SIGQUIT
54 SIGQUIT,
55 #endif
59 void SDL_InstallParachute(void)
61 /* Set a handler for any fatal signal not already handled */
62 int i;
63 #ifdef HAVE_SIGACTION
64 struct sigaction action;
66 for ( i=0; SDL_fatal_signals[i]; ++i ) {
67 sigaction(SDL_fatal_signals[i], NULL, &action);
68 if ( action.sa_handler == SIG_DFL ) {
69 action.sa_handler = SDL_Parachute;
70 sigaction(SDL_fatal_signals[i], &action, NULL);
73 #ifdef SIGALRM
74 /* Set SIGALRM to be ignored -- necessary on Solaris */
75 sigaction(SIGALRM, NULL, &action);
76 if ( action.sa_handler == SIG_DFL ) {
77 action.sa_handler = SIG_IGN;
78 sigaction(SIGALRM, &action, NULL);
80 #endif
81 #else
82 void (*ohandler)(int);
84 for ( i=0; SDL_fatal_signals[i]; ++i ) {
85 ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
86 if ( ohandler != SIG_DFL ) {
87 signal(SDL_fatal_signals[i], ohandler);
90 #endif /* HAVE_SIGACTION */
91 return;
94 void SDL_UninstallParachute(void)
96 /* Remove a handler for any fatal signal handled */
97 int i;
98 #ifdef HAVE_SIGACTION
99 struct sigaction action;
101 for ( i=0; SDL_fatal_signals[i]; ++i ) {
102 sigaction(SDL_fatal_signals[i], NULL, &action);
103 if ( action.sa_handler == SDL_Parachute ) {
104 action.sa_handler = SIG_DFL;
105 sigaction(SDL_fatal_signals[i], &action, NULL);
108 #else
109 void (*ohandler)(int);
111 for ( i=0; SDL_fatal_signals[i]; ++i ) {
112 ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
113 if ( ohandler != SDL_Parachute ) {
114 signal(SDL_fatal_signals[i], ohandler);
117 #endif /* HAVE_SIGACTION */
120 #else
122 /* No signals on this platform, nothing to do.. */
124 void SDL_InstallParachute(void)
126 return;
129 void SDL_UninstallParachute(void)
131 return;
134 #endif /* HAVE_SIGNAL_H */