Skip to content

Commit 69ff3e5

Browse files
committed
add netbsd implementation
1 parent 648a4f4 commit 69ff3e5

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

netbsd/hid.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct hid_device_ {
4545
int device_handle;
4646
int blocking;
4747
wchar_t *last_error_str;
48+
wchar_t *last_read_error_str;
4849
struct hid_device_info *device_info;
4950
size_t poll_handles_length;
5051
struct pollfd poll_handles[256];
@@ -143,6 +144,18 @@ static void register_device_error_format(hid_device *dev, const char *format, ..
143144
va_end(args);
144145
}
145146

147+
static void register_device_read_error(hid_device *dev, const char *msg)
148+
{
149+
register_error_str(&dev->last_read_error_str, msg);
150+
}
151+
152+
static void register_device_read_error_format(hid_device *dev, const char *format, ...)
153+
{
154+
va_list args;
155+
va_start(args, format);
156+
register_error_str_vformat(&dev->last_read_error_str, format, args);
157+
va_end(args);
158+
}
146159

147160
/*
148161
* Gets the size of the HID item at the given position
@@ -878,9 +891,11 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char
878891
struct pollfd *ph;
879892
ssize_t n;
880893

894+
register_device_read_error(dev, NULL);
895+
881896
res = poll(dev->poll_handles, dev->poll_handles_length, milliseconds);
882897
if (res == -1) {
883-
register_device_error_format(dev, "error while polling: %s", strerror(errno));
898+
register_device_read_error_format(dev, "error while polling: %s", strerror(errno));
884899
return -1;
885900
}
886901

@@ -891,7 +906,7 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char
891906
ph = &dev->poll_handles[i];
892907

893908
if (ph->revents & (POLLERR | POLLHUP | POLLNVAL)) {
894-
register_device_error(dev, "device IO error while polling");
909+
register_device_read_error(dev, "device IO error while polling");
895910
return -1;
896911
}
897912

@@ -907,7 +922,7 @@ int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char
907922
if (errno == EAGAIN || errno == EINPROGRESS)
908923
n = 0;
909924
else
910-
register_device_error_format(dev, "error while reading: %s", strerror(errno));
925+
register_device_read_error_format(dev, "error while reading: %s", strerror(errno));
911926
}
912927

913928
return n;
@@ -918,6 +933,13 @@ int HID_API_EXPORT HID_API_CALL hid_read(hid_device *dev, unsigned char *data, s
918933
return hid_read_timeout(dev, data, length, (dev->blocking) ? -1 : 0);
919934
}
920935

936+
HID_API_EXPORT const wchar_t* HID_API_CALL hid_read_error(hid_device *dev)
937+
{
938+
if (dev->last_read_error_str == NULL)
939+
return L"Success";
940+
return dev->last_read_error_str;
941+
}
942+
921943
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *dev, int nonblock)
922944
{
923945
dev->blocking = !nonblock;
@@ -949,8 +971,8 @@ void HID_API_EXPORT HID_API_CALL hid_close(hid_device *dev)
949971
if (!dev)
950972
return;
951973

952-
/* Free the device error message */
953-
register_device_error(dev, NULL);
974+
free(dev->last_error_str);
975+
free(dev->last_read_error_str);
954976

955977
hid_free_enumeration(dev->device_info);
956978

0 commit comments

Comments
 (0)