Include stdbool.h when using Visual Studio 2017+

Also cleaned up some incorrect return values from bool functions.
This commit is contained in:
Sam Lantinga 2024-10-01 09:57:05 -07:00
parent 522321b7c9
commit 4fa92d233d
9 changed files with 17 additions and 16 deletions

View File

@ -46,6 +46,7 @@
#ifndef __cplusplus
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(_MSC_VER) && (_MSC_VER >= 1910 /* Visual Studio 2017 */)) || \
defined(SDL_INCLUDE_STDBOOL_H)
#include <stdbool.h>
#elif !defined(__bool_true_false_are_defined) && !defined(bool)

View File

@ -306,12 +306,12 @@ char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid)
BOOL WIN_IsEqualGUID(const GUID *a, const GUID *b)
{
return SDL_memcmp(a, b, sizeof(*a)) == 0;
return (SDL_memcmp(a, b, sizeof(*a)) == 0);
}
BOOL WIN_IsEqualIID(REFIID a, REFIID b)
{
return SDL_memcmp(a, b, sizeof(*a)) == 0;
return (SDL_memcmp(a, b, sizeof(*a)) == 0);
}
void WIN_RECTToRect(const RECT *winrect, SDL_Rect *sdlrect)

View File

@ -45,7 +45,7 @@ bool SDL_SYS_EnumerateDirectory(const char *path, const char *dirname, SDL_Enume
const size_t patternlen = SDL_strlen(path) + 3;
char *pattern = (char *) SDL_malloc(patternlen);
if (!pattern) {
return -1;
return false;
}
// you need a wildcard to enumerate through FindFirstFileEx(), but the wildcard is only checked in the
@ -56,15 +56,14 @@ bool SDL_SYS_EnumerateDirectory(const char *path, const char *dirname, SDL_Enume
WCHAR *wpattern = WIN_UTF8ToStringW(pattern);
SDL_free(pattern);
if (!wpattern) {
return -1;
return false;
}
WIN32_FIND_DATAW entw;
HANDLE dir = FindFirstFileExW(wpattern, FindExInfoStandard, &entw, FindExSearchNameMatch, NULL, 0);
SDL_free(wpattern);
if (dir == INVALID_HANDLE_VALUE) {
WIN_SetError("Failed to enumerate directory");
return -1;
return WIN_SetError("Failed to enumerate directory");
}
do {

View File

@ -518,7 +518,7 @@ bool SDL_GetHapticEffectStatus(SDL_Haptic *haptic, int effect)
SDL_ClearError();
return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]);
return (SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]) > 0);
}
bool SDL_SetHapticGain(SDL_Haptic *haptic, int gain)

View File

@ -455,7 +455,7 @@ bool SDL_DINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick)
return false;
}
return WIN_IsEqualGUID(&hap_instance.guidInstance, &joy_instance.guidInstance);
return (WIN_IsEqualGUID(&hap_instance.guidInstance, &joy_instance.guidInstance) == TRUE);
}
bool SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick)
@ -1052,13 +1052,14 @@ int SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *e
ret = IDirectInputEffect_GetEffectStatus(effect->hweffect->ref, &status);
if (FAILED(ret)) {
return DI_SetError("Getting effect status", ret);
DI_SetError("Getting effect status", ret);
return -1;
}
if (status == 0) {
return false;
return 0;
}
return true;
return 1;
}
bool SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain)

View File

@ -1505,7 +1505,7 @@ bool SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy)
SDL_LockJoysticks();
{
CHECK_JOYSTICK_MAGIC(joystick, -1);
CHECK_JOYSTICK_MAGIC(joystick, false);
if (ball < joystick->nballs) {
if (dx) {

View File

@ -95,7 +95,7 @@ static bool STEAM_ReadStorageFile(void *userdata, const char *path, void *destin
static bool STEAM_WriteStorageFile(void *userdata, const char *path, const void *source, Uint64 length)
{
int result = false;
bool result = false;
STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata;
void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016();
if (steamremotestorage == NULL) {

View File

@ -119,7 +119,7 @@ static bool SDL_WaitConditionTimeoutNS_cv(SDL_Condition *_cond, SDL_Mutex *_mute
mutex->count = 0;
mutex->owner = 0;
result = pSleepConditionVariableSRW(&cond->cond, &mutex->srw, timeout, 0);
result = (pSleepConditionVariableSRW(&cond->cond, &mutex->srw, timeout, 0) == TRUE);
// The mutex is owned by us again, regardless of status of the wait
SDL_assert(mutex->count == 0 && mutex->owner == 0);
@ -130,7 +130,7 @@ static bool SDL_WaitConditionTimeoutNS_cv(SDL_Condition *_cond, SDL_Mutex *_mute
SDL_assert(SDL_mutex_impl_active.Type == SDL_MUTEX_CS);
result = pSleepConditionVariableCS(&cond->cond, &mutex->cs, timeout);
result = (pSleepConditionVariableCS(&cond->cond, &mutex->cs, timeout) == TRUE);
}
return result;

View File

@ -157,7 +157,7 @@ static void SDL_LockMutex_cs(SDL_Mutex *mutex_) SDL_NO_THREAD_SAFETY_ANALYSIS /
static bool SDL_TryLockMutex_cs(SDL_Mutex *mutex_)
{
SDL_mutex_cs *mutex = (SDL_mutex_cs *)mutex_;
return TryEnterCriticalSection(&mutex->cs);
return (TryEnterCriticalSection(&mutex->cs) == TRUE);
}
static void SDL_UnlockMutex_cs(SDL_Mutex *mutex_) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes