SDL: Updated check for stdbool.h

From 039148fb0ebf7017ff9e603e2fc25f603dae0204 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 28 Sep 2024 14:39:14 -0700
Subject: [PATCH] Updated check for stdbool.h

If you're building in a C99 or newer environment, we'll automatically include stdbool.h.

If you're building in a C89 or C90 environment, we'll assume that stdbool.h isn't available and define bool as an unsigned char. If you have a working stdbool.h and want SDL to use it, you can either include stdbool.h before SDL headers, or define SDL_INCLUDE_STDBOOL_H in your project.

Closes https://github.com/libsdl-org/SDL/pull/10980
---
 include/SDL3/SDL_stdinc.h                | 35 ++++++++++--------------
 include/SDL3/SDL_test_crc32.h            |  2 ++
 include/SDL3/SDL_test_memory.h           |  2 ++
 src/joystick/gdk/SDL_gameinputjoystick.c |  1 -
 4 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/include/SDL3/SDL_stdinc.h b/include/SDL3/SDL_stdinc.h
index e12cf1096e8fd..c83a0b90f5e7c 100644
--- a/include/SDL3/SDL_stdinc.h
+++ b/include/SDL3/SDL_stdinc.h
@@ -34,34 +34,27 @@
 
 #include <SDL3/SDL_platform_defines.h>
 
-/* Most everything except Visual Studio 2013 and earlier has stdbool.h now */
-#if defined(_MSC_VER) && (_MSC_VER < 1910)
-#define SDL_DEFINE_STDBOOL
-#endif
-/* gcc-2.95 had non-standard stdbool.h */
-#if defined(__GNUC__) && (__GNUC__ < 3)
-#define SDL_DEFINE_STDBOOL
-#endif
+#include <stdarg.h>
+#include <stdint.h>
+#include <string.h>
+#include <wchar.h>
 
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
+    defined(SDL_INCLUDE_INTTYPES_H)
 #include <inttypes.h>
 #endif
-#include <stdarg.h>
+
 #ifndef __cplusplus
-#ifdef SDL_DEFINE_STDBOOL
-#ifndef __bool_true_false_are_defined
-#define __bool_true_false_are_defined 1
-#define bool  uint8_t
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
+    defined(SDL_INCLUDE_STDBOOL_H)
+#include <stdbool.h>
+#elif !defined(__bool_true_false_are_defined) && !defined(bool)
+#define bool  unsigned char
 #define false 0
 #define true  1
+#define __bool_true_false_are_defined 1
 #endif
-#else
-#include <stdbool.h>
-#endif
-#endif
-#include <stdint.h>
-#include <string.h>
-#include <wchar.h>
+#endif /* !__cplusplus */
 
 #ifndef SDL_DISABLE_ALLOCA
 # ifndef alloca
diff --git a/include/SDL3/SDL_test_crc32.h b/include/SDL3/SDL_test_crc32.h
index 49c4cf21d5e47..62ece2afa87b6 100644
--- a/include/SDL3/SDL_test_crc32.h
+++ b/include/SDL3/SDL_test_crc32.h
@@ -34,6 +34,8 @@
 #ifndef SDL_test_crc32_h_
 #define SDL_test_crc32_h_
 
+#include <SDL3/SDL_stdinc.h>
+
 #include <SDL3/SDL_begin_code.h>
 /* Set up for C function definitions, even when using C++ */
 #ifdef __cplusplus
diff --git a/include/SDL3/SDL_test_memory.h b/include/SDL3/SDL_test_memory.h
index a1f8b1b3c0d53..16b2f63305f32 100644
--- a/include/SDL3/SDL_test_memory.h
+++ b/include/SDL3/SDL_test_memory.h
@@ -30,6 +30,8 @@
 #ifndef SDL_test_memory_h_
 #define SDL_test_memory_h_
 
+#include <SDL3/SDL_stdinc.h>
+
 #include <SDL3/SDL_begin_code.h>
 /* Set up for C function definitions, even when using C++ */
 #ifdef __cplusplus
diff --git a/src/joystick/gdk/SDL_gameinputjoystick.c b/src/joystick/gdk/SDL_gameinputjoystick.c
index bf60aded52cae..77ce854f4715c 100644
--- a/src/joystick/gdk/SDL_gameinputjoystick.c
+++ b/src/joystick/gdk/SDL_gameinputjoystick.c
@@ -25,7 +25,6 @@
 #include "../SDL_sysjoystick.h"
 #include "../usb_ids.h"
 
-#include <stdbool.h>
 #define COBJMACROS
 #include <gameinput.h>