SDL.c 19 KB

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