Skip to content

Commit 277cac9

Browse files
hid: add error data to hid_device structure
Store libusb error code so it can be retrieved later. Includes the original error code as well as a context-specific message which the libusb documentation sometimes specifies for each function. Code which uses those functions are meant to set the contextual message whenever possible. The code is initialized to a success state which implies no errors yet. The contextual error message is initialized to NULL and is not freed when the device is closed. It is meant to point at string literals.
1 parent 69db339 commit 277cac9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

libusb/hid.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ struct hid_device_ {
123123
#ifdef DETACH_KERNEL_DRIVER
124124
int is_driver_detached;
125125
#endif
126+
127+
int error;
128+
const char *error_context;
126129
};
127130

128131
static struct hid_api_version api_version = {
@@ -140,6 +143,8 @@ static hid_device *new_hid_device(void)
140143
{
141144
hid_device *dev = (hid_device*) calloc(1, sizeof(hid_device));
142145
dev->blocking = 1;
146+
dev->error = LIBUSB_SUCCESS;
147+
dev->error_context = NULL;
143148

144149
hidapi_thread_state_init(&dev->thread_state);
145150

0 commit comments

Comments
 (0)