SDL.c 18 KB

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