Fix C89 declaration for macOS modules.

Since Clang 14, `-Wdeclaration-after-statement` is enforced on every
standard.
This commit is contained in:
Pierre Wendling
2022-06-27 15:43:17 -04:00
committed by Sam Lantinga
parent e4a8087551
commit 6c536afdb7
17 changed files with 375 additions and 270 deletions

View File

@@ -156,11 +156,12 @@ static hid_device *new_hid_device(void)
static void free_hid_device(hid_device *dev)
{
struct input_report *rpt;
if (!dev)
return;
/* Delete any input reports still left over. */
struct input_report *rpt = dev->input_reports;
rpt = dev->input_reports;
while (rpt) {
struct input_report *next = rpt->next;
free(rpt->data);
@@ -260,14 +261,12 @@ static int get_string_property(IOHIDDeviceRef device, CFStringRef prop, wchar_t
buf[0] = 0;
if (str && CFGetTypeID(str) == CFStringGetTypeID()) {
len --;
CFIndex str_len = CFStringGetLength(str);
CFIndex used_buf_len, chars_copied;
CFRange range;
CFIndex str_len = CFStringGetLength(str);
len --;
range.location = 0;
range.length = (str_len > len)? len: str_len;
CFIndex used_buf_len;
CFIndex chars_copied;
chars_copied = CFStringGetBytes(str,
range,
kCFStringEncodingUTF32LE,
@@ -299,14 +298,12 @@ static int get_string_property_utf8(IOHIDDeviceRef device, CFStringRef prop, cha
buf[0] = 0;
if (str && CFGetTypeID(str) == CFStringGetTypeID()) {
len--;
CFIndex str_len = CFStringGetLength(str);
CFIndex used_buf_len, chars_copied;
CFRange range;
CFIndex str_len = CFStringGetLength(str);
len--;
range.location = 0;
range.length = (str_len > len)? len: str_len;
CFIndex used_buf_len;
CFIndex chars_copied;
chars_copied = CFStringGetBytes(str,
range,
kCFStringEncodingUTF8,
@@ -517,6 +514,8 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
struct hid_device_info *root = NULL; // return object
struct hid_device_info *cur_dev = NULL;
CFIndex num_devices;
CFSetRef device_set;
IOHIDDeviceRef *device_array;
int i;
/* Set up the HID Manager if it hasn't been done */
@@ -527,7 +526,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
process_pending_events();
/* Get a list of the Devices */
CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr);
device_set = IOHIDManagerCopyDevices(hid_mgr);
if (!device_set)
return NULL;
@@ -537,7 +536,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
CFRelease(device_set);
return NULL;
}
IOHIDDeviceRef *device_array = (IOHIDDeviceRef*)calloc(num_devices, sizeof(IOHIDDeviceRef));
device_array = (IOHIDDeviceRef*)calloc(num_devices, sizeof(IOHIDDeviceRef));
CFSetGetValues(device_set, (const void **) device_array);
/* Iterate over each device, making an entry for it. */
@@ -733,13 +732,14 @@ static void perform_signal_callback(void *context)
static void *read_thread(void *param)
{
hid_device *dev = (hid_device *)param;
CFRunLoopSourceContext ctx;
SInt32 code;
/* Move the device's run loop to this thread. */
IOHIDDeviceScheduleWithRunLoop(dev->device_handle, CFRunLoopGetCurrent(), dev->run_loop_mode);
/* Create the RunLoopSource which is used to signal the
event loop to stop when hid_close() is called. */
CFRunLoopSourceContext ctx;
memset(&ctx, 0, sizeof(ctx));
ctx.version = 0;
ctx.info = dev;
@@ -756,7 +756,6 @@ static void *read_thread(void *param)
/* Run the Event Loop. CFRunLoopRunInMode() will dispatch HID input
reports into the hid_report_callback(). */
SInt32 code;
while (!dev->shutdown_thread && !dev->disconnected) {
code = CFRunLoopRunInMode(dev->run_loop_mode, 1000/*sec*/, FALSE);
/* Return if the device has been disconnected */
@@ -796,10 +795,12 @@ static void *read_thread(void *param)
hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
{
int i;
int i;
hid_device *dev = NULL;
CFIndex num_devices;
CFSetRef device_set;
IOHIDDeviceRef *device_array;
dev = new_hid_device();
/* Set up the HID Manager if it hasn't been done */
@@ -809,10 +810,10 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
/* give the IOHIDManager a chance to update itself */
process_pending_events();
CFSetRef device_set = IOHIDManagerCopyDevices(hid_mgr);
device_set = IOHIDManagerCopyDevices(hid_mgr);
num_devices = CFSetGetCount(device_set);
IOHIDDeviceRef *device_array = (IOHIDDeviceRef *)calloc(num_devices, sizeof(IOHIDDeviceRef));
device_array = (IOHIDDeviceRef *)calloc(num_devices, sizeof(IOHIDDeviceRef));
CFSetGetValues(device_set, (const void **) device_array);
for (i = 0; i < num_devices; i++) {
char cbuf[BUF_LEN];
@@ -824,6 +825,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
IOReturn ret = IOHIDDeviceOpen(os_dev, kIOHIDOptionsTypeNone);
if (ret == kIOReturnSuccess) {
char str[32];
struct hid_device_list_node *node;
free(device_array);
CFRelease(device_set);
@@ -845,7 +847,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
os_dev, dev->input_report_buf, dev->max_input_report_len,
&hid_report_callback, dev);
struct hid_device_list_node *node = (struct hid_device_list_node *)calloc(1, sizeof(struct hid_device_list_node));
node = (struct hid_device_list_node *)calloc(1, sizeof(struct hid_device_list_node));
node->dev = dev;
node->next = device_list;
device_list = node;
@@ -1083,13 +1085,13 @@ int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data,
{
CFIndex len = length;
IOReturn res;
int skipped_report_id = 0, report_number;
/* Return if the device has been unplugged. */
if (dev->disconnected)
return -1;
int skipped_report_id = 0;
int report_number = data[0];
report_number = data[0];
if (report_number == 0x0) {
/* Offset the return buffer by 1, so that the report ID
will remain in byte 0. */