src/SDL.c
author Ozkan Sezer
Wed, 20 Nov 2019 02:47:40 +0300
changeset 13260 688fd43988a5
parent 13202 1254722e1722
child 13422 fd6a12de91c7
permissions -rw-r--r--
SDL.c (SDL_ExitProcess): unconstify its param to match its declaration.
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@12503
     3
  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
slouken@0
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@0
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@0
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@0
    20
*/
icculus@8093
    21
#include "./SDL_internal.h"
slouken@0
    22
slouken@7828
    23
#if defined(__WIN32__)
slouken@7828
    24
#include "core/windows/SDL_windows.h"
sezeroz@13148
    25
#elif defined(__OS2__)
sezeroz@13148
    26
#include <stdlib.h> /* For _exit() */
slouken@13139
    27
#elif !defined(__WINRT__)
sezeroz@13148
    28
#include <unistd.h> /* For _exit(), etc. */
slouken@7828
    29
#endif
slouken@7828
    30
icculus@13132
    31
#if defined(__EMSCRIPTEN__)
icculus@13132
    32
#include <emscripten.h>
icculus@13132
    33
#endif
icculus@13132
    34
slouken@0
    35
/* Initialization code for SDL */
slouken@0
    36
slouken@1361
    37
#include "SDL.h"
jorgen@6866
    38
#include "SDL_bits.h"
slouken@5310
    39
#include "SDL_revision.h"
slouken@4472
    40
#include "SDL_assert_c.h"
slouken@7360
    41
#include "events/SDL_events_c.h"
slouken@4472
    42
#include "haptic/SDL_haptic_c.h"
slouken@4472
    43
#include "joystick/SDL_joystick_c.h"
slouken@12130
    44
#include "sensor/SDL_sensor_c.h"
slouken@3647
    45
slouken@0
    46
/* Initialization/Cleanup routines */
slouken@1361
    47
#if !SDL_TIMERS_DISABLED
slouken@10609
    48
# include "timer/SDL_timer_c.h"
slouken@0
    49
#endif
slouken@7110
    50
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@2713
    51
extern int SDL_HelperWindowCreate(void);
slouken@2713
    52
extern int SDL_HelperWindowDestroy(void);
slouken@2713
    53
#endif
slouken@0
    54
slouken@3647
    55
icculus@13118
    56
/* This is not declared in any header, although it is shared between some
icculus@13118
    57
    parts of SDL, because we don't want anything calling it without an
icculus@13118
    58
    extremely good reason. */
sylvain@13202
    59
extern SDL_NORETURN void SDL_ExitProcess(int exitcode);
sezeroz@13260
    60
SDL_NORETURN void SDL_ExitProcess(int exitcode)
icculus@13118
    61
{
icculus@13118
    62
#ifdef __WIN32__
icculus@13118
    63
    /* "if you do not know the state of all threads in your process, it is
icculus@13118
    64
       better to call TerminateProcess than ExitProcess"
icculus@13118
    65
       https://msdn.microsoft.com/en-us/library/windows/desktop/ms682658(v=vs.85).aspx */
icculus@13118
    66
    TerminateProcess(GetCurrentProcess(), exitcode);
icculus@13118
    67
    /* MingW doesn't have TerminateProcess marked as noreturn, so add an
icculus@13118
    68
       ExitProcess here that will never be reached but make MingW happy. */
icculus@13118
    69
    ExitProcess(exitcode);
icculus@13118
    70
#elif defined(__EMSCRIPTEN__)
icculus@13118
    71
    emscripten_cancel_main_loop();  /* this should "kill" the app. */
icculus@13118
    72
    emscripten_force_exit(exitcode);  /* this should "kill" the app. */
icculus@13118
    73
    exit(exitcode);
icculus@13118
    74
#elif defined(__HAIKU__)  /* Haiku has _Exit, but it's not marked noreturn. */
icculus@13118
    75
    _exit(exitcode);
icculus@13118
    76
#elif defined(HAVE__EXIT) /* Upper case _Exit() */
icculus@13118
    77
    _Exit(exitcode);
icculus@13118
    78
#else
icculus@13118
    79
    _exit(exitcode);
icculus@13118
    80
#endif
icculus@13118
    81
}
icculus@13118
    82
icculus@13118
    83
slouken@0
    84
/* The initialized subsystems */
slouken@7281
    85
#ifdef SDL_MAIN_NEEDED
slouken@7281
    86
static SDL_bool SDL_MainIsReady = SDL_FALSE;
slouken@7281
    87
#else
slouken@7281
    88
static SDL_bool SDL_MainIsReady = SDL_TRUE;
slouken@7281
    89
#endif
slouken@6690
    90
static SDL_bool SDL_bInMainQuit = SDL_FALSE;
jorgen@6866
    91
static Uint8 SDL_SubsystemRefCount[ 32 ];
slouken@0
    92
jorgen@6866
    93
/* Private helper to increment a subsystem's ref counter. */
jorgen@6867
    94
static void
jorgen@6867
    95
SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
jorgen@6866
    96
{
jorgen@6866
    97
    int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
jorgen@6866
    98
    SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255);
jorgen@6866
    99
    ++SDL_SubsystemRefCount[subsystem_index];
jorgen@6866
   100
}
jorgen@6866
   101
jorgen@6866
   102
/* Private helper to decrement a subsystem's ref counter. */
jorgen@6867
   103
static void
jorgen@6867
   104
SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
slouken@6690
   105
{
jorgen@6866
   106
    int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
jorgen@6866
   107
    if (SDL_SubsystemRefCount[subsystem_index] > 0) {
jorgen@6866
   108
        --SDL_SubsystemRefCount[subsystem_index];
jorgen@6866
   109
    }
jorgen@6866
   110
}
jorgen@6866
   111
jorgen@6866
   112
/* Private helper to check if a system needs init. */
jorgen@6866
   113
static SDL_bool
jorgen@6927
   114
SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
jorgen@6866
   115
{
jorgen@6927
   116
    int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
jorgen@6866
   117
    SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255);
icculus@10925
   118
    return (SDL_SubsystemRefCount[subsystem_index] == 0) ? SDL_TRUE : SDL_FALSE;
jorgen@6866
   119
}
jorgen@6866
   120
jorgen@6866
   121
/* Private helper to check if a system needs to be quit. */
jorgen@6866
   122
static SDL_bool
jorgen@6866
   123
SDL_PrivateShouldQuitSubsystem(Uint32 subsystem) {
jorgen@6866
   124
    int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
jorgen@6866
   125
    if (SDL_SubsystemRefCount[subsystem_index] == 0) {
jorgen@6866
   126
      return SDL_FALSE;
jorgen@6866
   127
    }
jorgen@6866
   128
jorgen@6866
   129
    /* If we're in SDL_Quit, we shut down every subsystem, even if refcount
jorgen@6866
   130
     * isn't zero.
jorgen@6866
   131
     */
icculus@10925
   132
    return (SDL_SubsystemRefCount[subsystem_index] == 1 || SDL_bInMainQuit) ? SDL_TRUE : SDL_FALSE;
slouken@6690
   133
}
slouken@0
   134
slouken@7281
   135
void
slouken@7281
   136
SDL_SetMainReady(void)
slouken@7281
   137
{
slouken@7281
   138
    SDL_MainIsReady = SDL_TRUE;
slouken@7281
   139
}
slouken@7281
   140
slouken@1895
   141
int
slouken@1895
   142
SDL_InitSubSystem(Uint32 flags)
slouken@0
   143
{
slouken@7281
   144
    if (!SDL_MainIsReady) {
slouken@7281
   145
        SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
slouken@7281
   146
        return -1;
slouken@7281
   147
    }
slouken@7281
   148
icculus@7590
   149
    /* Clear the error message */
icculus@7590
   150
    SDL_ClearError();
icculus@7590
   151
slouken@10549
   152
    if ((flags & SDL_INIT_GAMECONTROLLER)) {
slouken@10549
   153
        /* game controller implies joystick */
slouken@10549
   154
        flags |= SDL_INIT_JOYSTICK;
slouken@10549
   155
    }
slouken@10549
   156
slouken@10549
   157
    if ((flags & (SDL_INIT_VIDEO|SDL_INIT_JOYSTICK))) {
slouken@10549
   158
        /* video or joystick implies events */
slouken@10549
   159
        flags |= SDL_INIT_EVENTS;
slouken@10549
   160
    }
slouken@10549
   161
icculus@7590
   162
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@12201
   163
    if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) {
slouken@12201
   164
        if (SDL_HelperWindowCreate() < 0) {
slouken@12201
   165
            return -1;
slouken@12201
   166
        }
slouken@12201
   167
    }
icculus@7590
   168
#endif
icculus@7590
   169
slouken@6128
   170
#if !SDL_TIMERS_DISABLED
slouken@8268
   171
    SDL_TicksInit();
slouken@0
   172
#endif
slouken@0
   173
slouken@7360
   174
    /* Initialize the event subsystem */
slouken@7360
   175
    if ((flags & SDL_INIT_EVENTS)) {
slouken@7360
   176
#if !SDL_EVENTS_DISABLED
slouken@7360
   177
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
icculus@12630
   178
            if (SDL_EventsInit() < 0) {
slouken@7360
   179
                return (-1);
slouken@7360
   180
            }
slouken@7360
   181
        }
slouken@7360
   182
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
slouken@7360
   183
#else
slouken@7360
   184
        return SDL_SetError("SDL not built with events support");
slouken@7360
   185
#endif
slouken@7360
   186
    }
slouken@7360
   187
jorgen@6866
   188
    /* Initialize the timer subsystem */
slouken@7360
   189
    if ((flags & SDL_INIT_TIMER)){
jorgen@6866
   190
#if !SDL_TIMERS_DISABLED
jorgen@6927
   191
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
jorgen@6924
   192
            if (SDL_TimerInit() < 0) {
jorgen@6924
   193
                return (-1);
jorgen@6924
   194
            }
jorgen@6866
   195
        }
jorgen@6866
   196
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER);
slouken@0
   197
#else
icculus@7037
   198
        return SDL_SetError("SDL not built with timer support");
jorgen@6866
   199
#endif
slouken@1895
   200
    }
slouken@0
   201
slouken@7360
   202
    /* Initialize the video subsystem */
slouken@7360
   203
    if ((flags & SDL_INIT_VIDEO)){
jorgen@6866
   204
#if !SDL_VIDEO_DISABLED
jorgen@6927
   205
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
jorgen@6924
   206
            if (SDL_VideoInit(NULL) < 0) {
jorgen@6924
   207
                return (-1);
jorgen@6924
   208
            }
jorgen@6866
   209
        }
jorgen@6866
   210
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO);
jorgen@6866
   211
#else
icculus@7037
   212
        return SDL_SetError("SDL not built with video support");
jorgen@6866
   213
#endif
jorgen@6866
   214
    }
jorgen@6866
   215
jorgen@6866
   216
    /* Initialize the audio subsystem */
slouken@7360
   217
    if ((flags & SDL_INIT_AUDIO)){
jorgen@6866
   218
#if !SDL_AUDIO_DISABLED
jorgen@6927
   219
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
jorgen@6924
   220
            if (SDL_AudioInit(NULL) < 0) {
jorgen@6924
   221
                return (-1);
jorgen@6924
   222
            }
slouken@1895
   223
        }
jorgen@6866
   224
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO);
jorgen@6866
   225
#else
icculus@7037
   226
        return SDL_SetError("SDL not built with audio support");
jorgen@6866
   227
#endif
jorgen@6866
   228
    }
slouken@6690
   229
jorgen@6866
   230
    /* Initialize the joystick subsystem */
slouken@7360
   231
    if ((flags & SDL_INIT_JOYSTICK)){
jorgen@6866
   232
#if !SDL_JOYSTICK_DISABLED
jorgen@6927
   233
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
jorgen@6924
   234
           if (SDL_JoystickInit() < 0) {
jorgen@6924
   235
               return (-1);
jorgen@6924
   236
           }
jorgen@6866
   237
        }
jorgen@6866
   238
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
slouken@0
   239
#else
icculus@7037
   240
        return SDL_SetError("SDL not built with joystick support");
slouken@0
   241
#endif
jorgen@6866
   242
    }
slouken@0
   243
slouken@7360
   244
    if ((flags & SDL_INIT_GAMECONTROLLER)){
jorgen@6866
   245
#if !SDL_JOYSTICK_DISABLED
jorgen@6927
   246
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
jorgen@6924
   247
            if (SDL_GameControllerInit() < 0) {
jorgen@6924
   248
                return (-1);
jorgen@6924
   249
            }
jorgen@6866
   250
        }
jorgen@6866
   251
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
jorgen@6866
   252
#else
icculus@7037
   253
        return SDL_SetError("SDL not built with joystick support");
jorgen@6866
   254
#endif
jorgen@6866
   255
    }
jorgen@6866
   256
slouken@2713
   257
    /* Initialize the haptic subsystem */
slouken@7360
   258
    if ((flags & SDL_INIT_HAPTIC)){
jorgen@6866
   259
#if !SDL_HAPTIC_DISABLED
jorgen@6927
   260
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
jorgen@6924
   261
            if (SDL_HapticInit() < 0) {
jorgen@6927
   262
                return (-1);
jorgen@6927
   263
            }
jorgen@6866
   264
        }
jorgen@6866
   265
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC);
slouken@2713
   266
#else
icculus@7037
   267
        return SDL_SetError("SDL not built with haptic (force feedback) support");
jorgen@6866
   268
#endif
slouken@2713
   269
    }
jorgen@6866
   270
slouken@12130
   271
    /* Initialize the sensor subsystem */
slouken@12130
   272
    if ((flags & SDL_INIT_SENSOR)){
slouken@12130
   273
#if !SDL_SENSOR_DISABLED
slouken@12130
   274
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_SENSOR)) {
slouken@12130
   275
            if (SDL_SensorInit() < 0) {
slouken@12130
   276
                return (-1);
slouken@12130
   277
            }
slouken@12130
   278
        }
slouken@12130
   279
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_SENSOR);
slouken@12130
   280
#else
slouken@12130
   281
        return SDL_SetError("SDL not built with sensor support");
slouken@12130
   282
#endif
slouken@12130
   283
    }
slouken@12130
   284
slouken@1895
   285
    return (0);
slouken@0
   286
}
slouken@0
   287
slouken@1895
   288
int
slouken@1895
   289
SDL_Init(Uint32 flags)
slouken@0
   290
{
icculus@7590
   291
    return SDL_InitSubSystem(flags);
slouken@0
   292
}
slouken@0
   293
slouken@1895
   294
void
slouken@1895
   295
SDL_QuitSubSystem(Uint32 flags)
slouken@0
   296
{
slouken@1895
   297
    /* Shut down requested initialized subsystems */
slouken@12130
   298
#if !SDL_SENSOR_DISABLED
slouken@12130
   299
    if ((flags & SDL_INIT_SENSOR)) {
slouken@12130
   300
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_SENSOR)) {
slouken@12201
   301
            SDL_SensorQuit();
slouken@12201
   302
        }
slouken@12130
   303
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_SENSOR);
slouken@12130
   304
    }
slouken@12130
   305
#endif
slouken@12130
   306
slouken@1361
   307
#if !SDL_JOYSTICK_DISABLED
jorgen@6866
   308
    if ((flags & SDL_INIT_GAMECONTROLLER)) {
slouken@7360
   309
        /* game controller implies joystick */
jorgen@6866
   310
        flags |= SDL_INIT_JOYSTICK;
jorgen@6866
   311
jorgen@6866
   312
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
jorgen@6866
   313
            SDL_GameControllerQuit();
slouken@7191
   314
        }
jorgen@6866
   315
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_GAMECONTROLLER);
jorgen@6866
   316
    }
slouken@6690
   317
jorgen@6866
   318
    if ((flags & SDL_INIT_JOYSTICK)) {
slouken@7360
   319
        /* joystick implies events */
slouken@7360
   320
        flags |= SDL_INIT_EVENTS;
slouken@7360
   321
jorgen@6866
   322
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
slouken@7191
   323
            SDL_JoystickQuit();
slouken@7191
   324
        }
jorgen@6866
   325
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_JOYSTICK);
slouken@1895
   326
    }
slouken@0
   327
#endif
jorgen@6866
   328
slouken@2713
   329
#if !SDL_HAPTIC_DISABLED
jorgen@6866
   330
    if ((flags & SDL_INIT_HAPTIC)) {
jorgen@6866
   331
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_HAPTIC)) {
slouken@7191
   332
            SDL_HapticQuit();
slouken@7191
   333
        }
jorgen@6866
   334
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_HAPTIC);
slouken@2713
   335
    }
slouken@2713
   336
#endif
jorgen@6866
   337
slouken@1361
   338
#if !SDL_AUDIO_DISABLED
jorgen@6866
   339
    if ((flags & SDL_INIT_AUDIO)) {
jorgen@6866
   340
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_AUDIO)) {
slouken@7191
   341
            SDL_AudioQuit();
slouken@7191
   342
        }
jorgen@6866
   343
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_AUDIO);
slouken@1895
   344
    }
slouken@0
   345
#endif
jorgen@6866
   346
slouken@1361
   347
#if !SDL_VIDEO_DISABLED
jorgen@6866
   348
    if ((flags & SDL_INIT_VIDEO)) {
slouken@7360
   349
        /* video implies events */
slouken@7360
   350
        flags |= SDL_INIT_EVENTS;
slouken@7360
   351
jorgen@6866
   352
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
slouken@7191
   353
            SDL_VideoQuit();
slouken@7191
   354
        }
jorgen@6866
   355
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_VIDEO);
slouken@1895
   356
    }
slouken@0
   357
#endif
jorgen@6866
   358
slouken@6128
   359
#if !SDL_TIMERS_DISABLED
jorgen@6866
   360
    if ((flags & SDL_INIT_TIMER)) {
jorgen@6866
   361
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_TIMER)) {
slouken@7191
   362
            SDL_TimerQuit();
slouken@7191
   363
        }
jorgen@6866
   364
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
slouken@6128
   365
    }
slouken@6128
   366
#endif
slouken@7360
   367
slouken@7360
   368
#if !SDL_EVENTS_DISABLED
slouken@7360
   369
    if ((flags & SDL_INIT_EVENTS)) {
slouken@7360
   370
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
icculus@12630
   371
            SDL_EventsQuit();
slouken@7360
   372
        }
slouken@7360
   373
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_EVENTS);
slouken@7360
   374
    }
slouken@7360
   375
#endif
slouken@0
   376
}
slouken@0
   377
slouken@1895
   378
Uint32
slouken@1895
   379
SDL_WasInit(Uint32 flags)
slouken@0
   380
{
jorgen@6866
   381
    int i;
jorgen@6866
   382
    int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
jorgen@6866
   383
    Uint32 initialized = 0;
jorgen@6866
   384
slouken@12422
   385
    /* Fast path for checking one flag */
slouken@12422
   386
    if (SDL_HasExactlyOneBitSet32(flags)) {
slouken@12422
   387
        int subsystem_index = SDL_MostSignificantBitIndex32(flags);
slouken@12422
   388
        return SDL_SubsystemRefCount[subsystem_index] ? flags : 0;
slouken@12422
   389
    }
slouken@12422
   390
slouken@1895
   391
    if (!flags) {
slouken@1895
   392
        flags = SDL_INIT_EVERYTHING;
slouken@1895
   393
    }
jorgen@6866
   394
jorgen@6866
   395
    num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
jorgen@6866
   396
jorgen@6866
   397
    /* Iterate over each bit in flags, and check the matching subsystem. */
jorgen@6866
   398
    for (i = 0; i < num_subsystems; ++i) {
jorgen@6866
   399
        if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
jorgen@6866
   400
            initialized |= (1 << i);
jorgen@6866
   401
        }
jorgen@6866
   402
jorgen@6866
   403
        flags >>= 1;
jorgen@6866
   404
    }
jorgen@6866
   405
jorgen@6866
   406
    return initialized;
slouken@0
   407
}
slouken@0
   408
slouken@1895
   409
void
slouken@1895
   410
SDL_Quit(void)
slouken@0
   411
{
jorgen@6866
   412
    SDL_bInMainQuit = SDL_TRUE;
jorgen@6866
   413
slouken@1895
   414
    /* Quit all subsystems */
slouken@7110
   415
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@2713
   416
    SDL_HelperWindowDestroy();
slouken@2713
   417
#endif
slouken@1895
   418
    SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
slouken@0
   419
slouken@8268
   420
#if !SDL_TIMERS_DISABLED
slouken@8268
   421
    SDL_TicksQuit();
slouken@8268
   422
#endif
slouken@8268
   423
slouken@5189
   424
    SDL_ClearHints();
slouken@3647
   425
    SDL_AssertionsQuit();
slouken@5221
   426
    SDL_LogResetPriorities();
slouken@6690
   427
jorgen@6866
   428
    /* Now that every subsystem has been quit, we reset the subsystem refcount
jorgen@6866
   429
     * and the list of initialized subsystems.
jorgen@6866
   430
     */
jorgen@6866
   431
    SDL_memset( SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount) );
jorgen@6866
   432
jorgen@6866
   433
    SDL_bInMainQuit = SDL_FALSE;
slouken@0
   434
}
slouken@0
   435
slouken@1895
   436
/* Get the library version number */
slouken@1895
   437
void
slouken@1895
   438
SDL_GetVersion(SDL_version * ver)
slouken@0
   439
{
slouken@1895
   440
    SDL_VERSION(ver);
slouken@0
   441
}
slouken@0
   442
slouken@2982
   443
/* Get the library source revision */
icculus@4419
   444
const char *
slouken@2996
   445
SDL_GetRevision(void)
slouken@2982
   446
{
slouken@2983
   447
    return SDL_REVISION;
slouken@2982
   448
}
slouken@2982
   449
slouken@5359
   450
/* Get the library source revision number */
slouken@5359
   451
int
slouken@5359
   452
SDL_GetRevisionNumber(void)
slouken@5359
   453
{
slouken@5359
   454
    return SDL_REVISION_NUMBER;
slouken@5359
   455
}
slouken@5359
   456
slouken@3319
   457
/* Get the name of the platform */
slouken@3319
   458
const char *
slouken@3319
   459
SDL_GetPlatform()
slouken@3319
   460
{
slouken@3319
   461
#if __AIX__
slouken@3319
   462
    return "AIX";
slouken@6441
   463
#elif __ANDROID__
slouken@6441
   464
    return "Android";
slouken@3319
   465
#elif __BSDI__
slouken@3319
   466
    return "BSDI";
slouken@3319
   467
#elif __DREAMCAST__
slouken@3319
   468
    return "Dreamcast";
philipp@9341
   469
#elif __EMSCRIPTEN__
philipp@9341
   470
    return "Emscripten";
slouken@3319
   471
#elif __FREEBSD__
slouken@3319
   472
    return "FreeBSD";
icculus@7346
   473
#elif __HAIKU__
icculus@7346
   474
    return "Haiku";
slouken@3319
   475
#elif __HPUX__
slouken@3319
   476
    return "HP-UX";
slouken@3319
   477
#elif __IRIX__
slouken@3319
   478
    return "Irix";
slouken@3319
   479
#elif __LINUX__
slouken@3319
   480
    return "Linux";
slouken@3319
   481
#elif __MINT__
slouken@3319
   482
    return "Atari MiNT";
slouken@3319
   483
#elif __MACOS__
slouken@3319
   484
    return "MacOS Classic";
slouken@3319
   485
#elif __MACOSX__
slouken@3319
   486
    return "Mac OS X";
slouken@8886
   487
#elif __NACL__
slouken@8886
   488
    return "NaCl";
slouken@3319
   489
#elif __NETBSD__
slouken@3319
   490
    return "NetBSD";
slouken@3319
   491
#elif __OPENBSD__
slouken@3319
   492
    return "OpenBSD";
slouken@3319
   493
#elif __OS2__
slouken@3319
   494
    return "OS/2";
slouken@3319
   495
#elif __OSF__
slouken@3319
   496
    return "OSF/1";
slouken@3319
   497
#elif __QNXNTO__
slouken@3319
   498
    return "QNX Neutrino";
slouken@3319
   499
#elif __RISCOS__
slouken@3319
   500
    return "RISC OS";
slouken@3319
   501
#elif __SOLARIS__
slouken@3319
   502
    return "Solaris";
slouken@5086
   503
#elif __WIN32__
slouken@3319
   504
    return "Windows";
dludwig@9223
   505
#elif __WINRT__
dludwig@9223
   506
    return "WinRT";
slime73@10340
   507
#elif __TVOS__
slime73@10340
   508
    return "tvOS";
slouken@3319
   509
#elif __IPHONEOS__
slouken@7592
   510
    return "iOS";
kimonline@7009
   511
#elif __PSP__
kimonline@7009
   512
    return "PlayStation Portable";
slouken@3319
   513
#else
slouken@3319
   514
    return "Unknown (see SDL_platform.h)";
slouken@3319
   515
#endif
slouken@3319
   516
}
slouken@3319
   517
slouken@12137
   518
SDL_bool
slouken@12137
   519
SDL_IsTablet()
slouken@12137
   520
{
slouken@12137
   521
#if __ANDROID__
slouken@12137
   522
    extern SDL_bool SDL_IsAndroidTablet(void);
slouken@12137
   523
    return SDL_IsAndroidTablet();
slouken@12137
   524
#elif __IPHONEOS__
slouken@12137
   525
    extern SDL_bool SDL_IsIPad(void);
slouken@12137
   526
    return SDL_IsIPad();
slouken@12137
   527
#else
slouken@12137
   528
    return SDL_FALSE;
slouken@12137
   529
#endif
slouken@12137
   530
}
slouken@12137
   531
slouken@11883
   532
#if defined(__WIN32__)
slouken@11883
   533
slouken@11885
   534
#if (!defined(HAVE_LIBC) || defined(__WATCOMC__)) && !defined(SDL_STATIC_LIB)
slouken@1465
   535
/* Need to include DllMain() on Watcom C for some reason.. */
slouken@1330
   536
slouken@1895
   537
BOOL APIENTRY
slouken@1895
   538
_DllMainCRTStartup(HANDLE hModule,
slouken@1895
   539
                   DWORD ul_reason_for_call, LPVOID lpReserved)
slouken@1330
   540
{
slouken@1895
   541
    switch (ul_reason_for_call) {
slouken@1895
   542
    case DLL_PROCESS_ATTACH:
slouken@1895
   543
    case DLL_THREAD_ATTACH:
slouken@1895
   544
    case DLL_THREAD_DETACH:
slouken@1895
   545
    case DLL_PROCESS_DETACH:
slouken@1895
   546
        break;
slouken@1895
   547
    }
slouken@1895
   548
    return TRUE;
slouken@1330
   549
}
slouken@11885
   550
#endif /* Building DLL */
slouken@1330
   551
slouken@11883
   552
#endif /* __WIN32__ */
slouken@11883
   553
jorgen@6927
   554
/* vi: set sts=4 ts=4 sw=4 expandtab: */