Pointer as bool (libsdl-org#7214)

This commit is contained in:
Sylvain
2023-11-09 22:29:15 +01:00
committed by Sam Lantinga
parent 23db971681
commit d8600f717e
371 changed files with 2448 additions and 2442 deletions

View File

@@ -47,7 +47,7 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev);
static SDL_bool SDL_UDEV_load_sym(const char *fn, void **addr)
{
*addr = SDL_LoadFunction(_this->udev_handle, fn);
if (*addr == NULL) {
if (!*addr) {
/* Don't call SDL_SetError(): SDL_LoadFunction already did. */
return SDL_FALSE;
}
@@ -96,7 +96,7 @@ static int SDL_UDEV_load_syms(void)
static SDL_bool SDL_UDEV_hotplug_update_available(void)
{
if (_this->udev_mon != NULL) {
if (_this->udev_mon) {
const int fd = _this->syms.udev_monitor_get_fd(_this->udev_mon);
if (SDL_IOReady(fd, SDL_IOR_READ, 0)) {
return SDL_TRUE;
@@ -109,9 +109,9 @@ int SDL_UDEV_Init(void)
{
int retval = 0;
if (_this == NULL) {
if (!_this) {
_this = (SDL_UDEV_PrivateData *)SDL_calloc(1, sizeof(*_this));
if (_this == NULL) {
if (!_this) {
return SDL_OutOfMemory();
}
@@ -126,13 +126,13 @@ int SDL_UDEV_Init(void)
*/
_this->udev = _this->syms.udev_new();
if (_this->udev == NULL) {
if (!_this->udev) {
SDL_UDEV_Quit();
return SDL_SetError("udev_new() failed");
}
_this->udev_mon = _this->syms.udev_monitor_new_from_netlink(_this->udev, "udev");
if (_this->udev_mon == NULL) {
if (!_this->udev_mon) {
SDL_UDEV_Quit();
return SDL_SetError("udev_monitor_new_from_netlink() failed");
}
@@ -152,7 +152,7 @@ int SDL_UDEV_Init(void)
void SDL_UDEV_Quit(void)
{
if (_this == NULL) {
if (!_this) {
return;
}
@@ -160,17 +160,17 @@ void SDL_UDEV_Quit(void)
if (_this->ref_count < 1) {
if (_this->udev_mon != NULL) {
if (_this->udev_mon) {
_this->syms.udev_monitor_unref(_this->udev_mon);
_this->udev_mon = NULL;
}
if (_this->udev != NULL) {
if (_this->udev) {
_this->syms.udev_unref(_this->udev);
_this->udev = NULL;
}
/* Remove existing devices */
while (_this->first != NULL) {
while (_this->first) {
SDL_UDEV_CallbackList *item = _this->first;
_this->first = _this->first->next;
SDL_free(item);
@@ -188,12 +188,12 @@ int SDL_UDEV_Scan(void)
struct udev_list_entry *devs = NULL;
struct udev_list_entry *item = NULL;
if (_this == NULL) {
if (!_this) {
return 0;
}
enumerate = _this->syms.udev_enumerate_new(_this->udev);
if (enumerate == NULL) {
if (!enumerate) {
SDL_UDEV_Quit();
return SDL_SetError("udev_enumerate_new() failed");
}
@@ -206,7 +206,7 @@ int SDL_UDEV_Scan(void)
for (item = devs; item; item = _this->syms.udev_list_entry_get_next(item)) {
const char *path = _this->syms.udev_list_entry_get_name(item);
struct udev_device *dev = _this->syms.udev_device_new_from_syspath(_this->udev, path);
if (dev != NULL) {
if (dev) {
device_event(SDL_UDEV_DEVICEADDED, dev);
_this->syms.udev_device_unref(dev);
}
@@ -223,12 +223,12 @@ SDL_bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16
struct udev_list_entry *item = NULL;
SDL_bool found = SDL_FALSE;
if (_this == NULL) {
if (!_this) {
return SDL_FALSE;
}
enumerate = _this->syms.udev_enumerate_new(_this->udev);
if (enumerate == NULL) {
if (!enumerate) {
SDL_SetError("udev_enumerate_new() failed");
return SDL_FALSE;
}
@@ -238,7 +238,7 @@ SDL_bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16
for (item = devs; item && !found; item = _this->syms.udev_list_entry_get_next(item)) {
const char *path = _this->syms.udev_list_entry_get_name(item);
struct udev_device *dev = _this->syms.udev_device_new_from_syspath(_this->udev, path);
if (dev != NULL) {
if (dev) {
const char *val = NULL;
const char *existing_path;
@@ -247,17 +247,17 @@ SDL_bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16
found = SDL_TRUE;
val = _this->syms.udev_device_get_property_value(dev, "ID_VENDOR_ID");
if (val != NULL) {
if (val) {
*vendor = (Uint16)SDL_strtol(val, NULL, 16);
}
val = _this->syms.udev_device_get_property_value(dev, "ID_MODEL_ID");
if (val != NULL) {
if (val) {
*product = (Uint16)SDL_strtol(val, NULL, 16);
}
val = _this->syms.udev_device_get_property_value(dev, "ID_REVISION");
if (val != NULL) {
if (val) {
*version = (Uint16)SDL_strtol(val, NULL, 16);
}
}
@@ -271,11 +271,11 @@ SDL_bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16
void SDL_UDEV_UnloadLibrary(void)
{
if (_this == NULL) {
if (!_this) {
return;
}
if (_this->udev_handle != NULL) {
if (_this->udev_handle) {
SDL_UnloadObject(_this->udev_handle);
_this->udev_handle = NULL;
}
@@ -285,7 +285,7 @@ int SDL_UDEV_LoadLibrary(void)
{
int retval = 0, i;
if (_this == NULL) {
if (!_this) {
return SDL_SetError("UDEV not initialized");
}
@@ -296,9 +296,9 @@ int SDL_UDEV_LoadLibrary(void)
#ifdef SDL_UDEV_DYNAMIC
/* Check for the build environment's libudev first */
if (_this->udev_handle == NULL) {
if (!_this->udev_handle) {
_this->udev_handle = SDL_LoadObject(SDL_UDEV_DYNAMIC);
if (_this->udev_handle != NULL) {
if (_this->udev_handle) {
retval = SDL_UDEV_load_syms();
if (retval < 0) {
SDL_UDEV_UnloadLibrary();
@@ -307,10 +307,10 @@ int SDL_UDEV_LoadLibrary(void)
}
#endif
if (_this->udev_handle == NULL) {
if (!_this->udev_handle) {
for (i = 0; i < SDL_arraysize(SDL_UDEV_LIBS); i++) {
_this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]);
if (_this->udev_handle != NULL) {
if (_this->udev_handle) {
retval = SDL_UDEV_load_syms();
if (retval < 0) {
SDL_UDEV_UnloadLibrary();
@@ -320,7 +320,7 @@ int SDL_UDEV_LoadLibrary(void)
}
}
if (_this->udev_handle == NULL) {
if (!_this->udev_handle) {
retval = -1;
/* Don't call SDL_SetError(): SDL_LoadObject already did. */
}
@@ -339,7 +339,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch
SDL_memset(bitmask, 0, bitmask_len * sizeof(*bitmask));
value = _this->syms.udev_device_get_sysattr_value(pdev, attr);
if (value == NULL) {
if (!value) {
return;
}
@@ -374,7 +374,7 @@ static int guess_device_class(struct udev_device *dev)
while (pdev && !_this->syms.udev_device_get_sysattr_value(pdev, "capabilities/ev")) {
pdev = _this->syms.udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL);
}
if (pdev == NULL) {
if (!pdev) {
return 0;
}
@@ -400,7 +400,7 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
SDL_UDEV_CallbackList *item;
path = _this->syms.udev_device_get_devnode(dev);
if (path == NULL) {
if (!path) {
return;
}
@@ -411,23 +411,23 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
/* udev rules reference: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c */
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK");
if (val != NULL && SDL_strcmp(val, "1") == 0) {
if (val && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_JOYSTICK;
}
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_ACCELEROMETER");
if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE) &&
val != NULL && SDL_strcmp(val, "1") == 0) {
val && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_JOYSTICK;
}
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_MOUSE");
if (val != NULL && SDL_strcmp(val, "1") == 0) {
if (val && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_MOUSE;
}
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN");
if (val != NULL && SDL_strcmp(val, "1") == 0) {
if (val && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN;
}
@@ -438,19 +438,19 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
Ref: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c#n183
*/
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_KEY");
if (val != NULL && SDL_strcmp(val, "1") == 0) {
if (val && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_HAS_KEYS;
}
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD");
if (val != NULL && SDL_strcmp(val, "1") == 0) {
if (val && SDL_strcmp(val, "1") == 0) {
devclass |= SDL_UDEV_DEVICE_KEYBOARD;
}
if (devclass == 0) {
/* Fall back to old style input classes */
val = _this->syms.udev_device_get_property_value(dev, "ID_CLASS");
if (val != NULL) {
if (val) {
if (SDL_strcmp(val, "joystick") == 0) {
devclass = SDL_UDEV_DEVICE_JOYSTICK;
} else if (SDL_strcmp(val, "mouse") == 0) {
@@ -470,7 +470,7 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
}
/* Process callbacks */
for (item = _this->first; item != NULL; item = item->next) {
for (item = _this->first; item; item = item->next) {
item->callback(type, devclass, path);
}
}
@@ -480,13 +480,13 @@ void SDL_UDEV_Poll(void)
struct udev_device *dev = NULL;
const char *action = NULL;
if (_this == NULL) {
if (!_this) {
return;
}
while (SDL_UDEV_hotplug_update_available()) {
dev = _this->syms.udev_monitor_receive_device(_this->udev_mon);
if (dev == NULL) {
if (!dev) {
break;
}
action = _this->syms.udev_device_get_action(dev);
@@ -507,13 +507,13 @@ int SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
{
SDL_UDEV_CallbackList *item;
item = (SDL_UDEV_CallbackList *)SDL_calloc(1, sizeof(SDL_UDEV_CallbackList));
if (item == NULL) {
if (!item) {
return SDL_OutOfMemory();
}
item->callback = cb;
if (_this->last == NULL) {
if (!_this->last) {
_this->first = _this->last = item;
} else {
_this->last->next = item;
@@ -528,14 +528,14 @@ void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
SDL_UDEV_CallbackList *item;
SDL_UDEV_CallbackList *prev = NULL;
if (_this == NULL) {
if (!_this) {
return;
}
for (item = _this->first; item != NULL; item = item->next) {
for (item = _this->first; item; item = item->next) {
/* found it, remove it. */
if (item->callback == cb) {
if (prev != NULL) {
if (prev) {
prev->next = item->next;
} else {
SDL_assert(_this->first == item);