From 1c37c339f672a6e878ef43022d44f376db765b94 Mon Sep 17 00:00:00 2001 From: COMBudda <151936846+COMBudda@users.noreply.github.com> Date: Tue, 28 Nov 2023 14:50:25 +0100 Subject: [PATCH] Update usb.c Add Windows handling to usb.c. Per https://libusb.sourceforge.io/api-1.0/group__libusb__poll.html libusb_get_pollfds() As file descriptors are a Unix-specific concept, this function is not available on Windows and will always return NULL. --- src/usb.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/usb.c b/src/usb.c index feafe9d2a..c751a69c6 100644 --- a/src/usb.c +++ b/src/usb.c @@ -262,10 +262,15 @@ static GSource *usb_source_new(struct sr_session *session, const struct libusb_pollfd **upollfds, **upfd; upollfds = libusb_get_pollfds(usb_ctx); + +/* There are no filehandles in Windows */ +#if !defined(__MINGW32__) if (!upollfds) { sr_err("Failed to get libusb file descriptors."); return NULL; } +#endif + source = g_source_new(&usb_source_funcs, sizeof(struct usb_source)); usource = (struct usb_source *)source; @@ -281,7 +286,9 @@ static GSource *usb_source_new(struct sr_session *session, usource->session = session; usource->usb_ctx = usb_ctx; usource->pollfds = g_ptr_array_new_full(8, &usb_source_free_pollfd); - + +/* There are no filehandles in Windows */ +#if !defined(__MINGW32__) for (upfd = upollfds; *upfd != NULL; upfd++) usb_pollfd_added((*upfd)->fd, (*upfd)->events, usource); @@ -292,7 +299,7 @@ static GSource *usb_source_new(struct sr_session *session, #endif libusb_set_pollfd_notifiers(usb_ctx, &usb_pollfd_added, &usb_pollfd_removed, usource); - +#endif return source; }