SDL_quit.c File Reference
`#include "../SDL_internal.h"`
`#include "SDL_hints.h"`
`#include "SDL_assert.h"`
`#include "SDL_events.h"`
`#include "SDL_events_c.h"`
Include dependency graph for SDL_quit.c:

Go to the source code of this file.

## Functions

static void | SDL_HandleSIG (int sig)
static int | SDL_QuitInit_Internal (void)
int | SDL_QuitInit (void)
static void | SDL_QuitQuit_Internal (void)
void | SDL_QuitQuit (void)
int | SDL_SendQuit (void)
void | SDL_SendPendingQuit (void)

## Variables

static SDL_bool | disable_signals = SDL_FALSE
static SDL_bool | send_quit_pending = SDL_FALSE

## Function Documentation

static void SDL_HandleSIG | ( | int | sig | ) |

static

Definition at line 39 of file SDL_quit.c.

References SDL_TRUE, and send_quit_pending.

Referenced by SDL_QuitInit_Internal(), and SDL_QuitQuit_Internal().

{
/* Reset the signal handler */
signal(sig, SDL_HandleSIG);
/* Send a quit event next time the event loop pumps. */
/* We can't send it in signal handler; malloc() might be interrupted! */
send_quit_pending = SDL_TRUE;
}
SDL_HandleSIG
static void SDL_HandleSIG(int sig)
Definition: SDL_quit.c:39
send_quit_pending
static SDL_bool send_quit_pending
Definition: SDL_quit.c:35
SDL_TRUE
Definition: SDL_stdinc.h:129

int SDL_QuitInit | ( | void |  | ) |

Definition at line 92 of file SDL_quit.c.

References disable_signals, SDL_atoi, SDL_GetHint, SDL_HINT_NO_SIGNAL_HANDLERS, and SDL_QuitInit_Internal().

Referenced by SDL_InitSubSystem().

{
const char *hint = SDL_GetHint(SDL_HINT_NO_SIGNAL_HANDLERS);
disable_signals = hint && (SDL_atoi(hint) == 1);
if (!disable_signals) {
return SDL_QuitInit_Internal();
}
return 0;
}
SDL_GetHint
#define SDL_GetHint
Definition: SDL_dynapi_overrides.h:197
disable_signals
static SDL_bool disable_signals
Definition: SDL_quit.c:34
SDL_atoi
#define SDL_atoi
Definition: SDL_dynapi_overrides.h:416
SDL_HINT_NO_SIGNAL_HANDLERS
#define SDL_HINT_NO_SIGNAL_HANDLERS
Tell SDL not to catch the SIGINT or SIGTERM signals.
Definition: SDL_hints.h:622
SDL_QuitInit_Internal
static int SDL_QuitInit_Internal(void)
Definition: SDL_quit.c:52

static int SDL_QuitInit_Internal | ( | void |  | ) |

static

Definition at line 52 of file SDL_quit.c.

References NULL, SDL_HandleSIG(), and void.

Referenced by SDL_QuitInit().

{
#ifdef HAVE_SIGACTION
struct sigaction action;
sigaction(SIGINT, NULL, &action);
#ifdef HAVE_SA_SIGACTION
if ( action.sa_handler == SIG_DFL && action.sa_sigaction == (void*)SIG_DFL ) {
#else
if ( action.sa_handler == SIG_DFL ) {
#endif
action.sa_handler = SDL_HandleSIG;
sigaction(SIGINT, &action, NULL);
}
sigaction(SIGTERM, NULL, &action);
#ifdef HAVE_SA_SIGACTION
if ( action.sa_handler == SIG_DFL && action.sa_sigaction == (void*)SIG_DFL ) {
#else
if ( action.sa_handler == SIG_DFL ) {
#endif
action.sa_handler = SDL_HandleSIG;
sigaction(SIGTERM, &action, NULL);
}
#elif HAVE_SIGNAL_H
void (*ohandler) (int);
/* Both SIGINT and SIGTERM are translated into quit interrupts */
ohandler = signal(SIGINT, SDL_HandleSIG);
if (ohandler != SIG_DFL)
signal(SIGINT, ohandler);
ohandler = signal(SIGTERM, SDL_HandleSIG);
if (ohandler != SIG_DFL)
signal(SIGTERM, ohandler);
#endif /* HAVE_SIGNAL_H */
/* That's it! */
return 0;
}
SDL_HandleSIG
static void SDL_HandleSIG(int sig)
Definition: SDL_quit.c:39
NULL
#define NULL
Definition: begin_code.h:143
void
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
Definition: SDL_dynapi_procs.h:93

void SDL_QuitQuit | ( | void |  | ) |

Definition at line 130 of file SDL_quit.c.

References disable_signals, and SDL_QuitQuit_Internal().

Referenced by SDL_QuitSubSystem().

{
if (!disable_signals) {
SDL_QuitQuit_Internal();
}
}
disable_signals
static SDL_bool disable_signals
Definition: SDL_quit.c:34
SDL_QuitQuit_Internal
static void SDL_QuitQuit_Internal(void)
Definition: SDL_quit.c:103

static void SDL_QuitQuit_Internal | ( | void |  | ) |

static

Definition at line 103 of file SDL_quit.c.

References NULL, SDL_HandleSIG(), and void.

Referenced by SDL_QuitQuit().

{
#ifdef HAVE_SIGACTION
struct sigaction action;
sigaction(SIGINT, NULL, &action);
if ( action.sa_handler == SDL_HandleSIG ) {
action.sa_handler = SIG_DFL;
sigaction(SIGINT, &action, NULL);
}
sigaction(SIGTERM, NULL, &action);
if ( action.sa_handler == SDL_HandleSIG ) {
action.sa_handler = SIG_DFL;
sigaction(SIGTERM, &action, NULL);
}
#elif HAVE_SIGNAL_H
void (*ohandler) (int);
ohandler = signal(SIGINT, SIG_DFL);
if (ohandler != SDL_HandleSIG)
signal(SIGINT, ohandler);
ohandler = signal(SIGTERM, SIG_DFL);
if (ohandler != SDL_HandleSIG)
signal(SIGTERM, ohandler);
#endif /* HAVE_SIGNAL_H */
}
SDL_HandleSIG
static void SDL_HandleSIG(int sig)
Definition: SDL_quit.c:39
NULL
#define NULL
Definition: begin_code.h:143
void
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
Definition: SDL_dynapi_procs.h:93

void SDL_SendPendingQuit | ( | void |  | ) |

Definition at line 146 of file SDL_quit.c.

References SDL_assert, SDL_SendQuit(), and send_quit_pending.

Referenced by SDL_PumpEvents().

{
if (send_quit_pending) {
SDL_SendQuit();
SDL_assert(!send_quit_pending);
}
}
send_quit_pending
static SDL_bool send_quit_pending
Definition: SDL_quit.c:35
SDL_SendQuit
int SDL_SendQuit(void)
Definition: SDL_quit.c:139
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:167

int SDL_SendQuit | ( | void |  | ) |

Definition at line 139 of file SDL_quit.c.

References SDL_FALSE, SDL_QUIT, SDL_SendAppEvent(), and send_quit_pending.

Referenced by SDL_SendPendingQuit(), and SDL_SendWindowEvent().

{
send_quit_pending = SDL_FALSE;
return SDL_SendAppEvent(SDL_QUIT);
}
SDL_QUIT
Definition: SDL_events.h:60
send_quit_pending
static SDL_bool send_quit_pending
Definition: SDL_quit.c:35
SDL_FALSE
Definition: SDL_stdinc.h:128
SDL_SendAppEvent
int SDL_SendAppEvent(SDL_EventType eventType)
Definition: SDL_events.c:622

## Variable Documentation

SDL_bool disable_signals = SDL_FALSE

static

Definition at line 34 of file SDL_quit.c.

Referenced by SDL_QuitInit(), and SDL_QuitQuit().

SDL_bool send_quit_pending = SDL_FALSE

static

Definition at line 35 of file SDL_quit.c.

Referenced by SDL_HandleSIG(), SDL_SendPendingQuit(), and SDL_SendQuit().