Skip to content

Commit 35c5e53

Browse files
hid: define easy error data setter function
Sets all error data, including an optional error message. Ensures any previous error data is freed before overwriting. Optional error message is meant to be used in the cases the libusb documentation goes into detail as to what happened.
1 parent e4d5d84 commit 35c5e53

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

libusb/hid.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,21 @@ static wchar_t *libusb_strerror_wchar(int error) {
409409
return utf8_to_wchar(s);
410410
}
411411

412+
static void set_error(hid_device *dev, int error, const wchar_t *custom_string)
413+
{
414+
if (dev->error_name) {
415+
free(dev->error_name);
416+
}
417+
418+
if (dev->error_string) {
419+
free(dev->error_string);
420+
}
421+
422+
dev->error = error;
423+
dev->error_name = libusb_error_name_wchar(error);
424+
dev->error_string = custom_string?
425+
wcsdup(custom_string) : libusb_strerror_wchar(error);
426+
}
412427

413428
/* This function returns a newly allocated wide string containing the USB
414429
device string numbered by the index. The returned string must be freed

0 commit comments

Comments
 (0)