Index: Makefile
===================================================================
RCS file: /cvsroot/pkgsrc/devel/libusb/Makefile,v
retrieving revision 1.47
diff -u -r1.47 Makefile
--- Makefile	20 Mar 2020 11:57:28 -0000	1.47
+++ Makefile	23 Jan 2022 18:14:04 -0000
@@ -1,7 +1,7 @@
 # $NetBSD: Makefile,v 1.47 2020/03/20 11:57:28 nia Exp $
 
 DISTNAME=	libusb-0.1.12
-PKGREVISION=	7
+PKGREVISION=	97
 CATEGORIES=	devel
 MASTER_SITES=	${MASTER_SITE_SOURCEFORGE:=libusb/}
 
Index: distinfo
===================================================================
RCS file: /cvsroot/pkgsrc/devel/libusb/distinfo,v
retrieving revision 1.31
diff -u -r1.31 distinfo
--- distinfo	26 Oct 2021 10:15:29 -0000	1.31
+++ distinfo	23 Jan 2022 18:14:04 -0000
@@ -6,7 +6,7 @@
 SHA1 (patch-aa) = 1da6c46e8b41d7846032922bbef8a0b5eb1ae68b
 SHA1 (patch-ab) = bc4756536ce7b2cc49d0c7c48c249f146f185839
 SHA1 (patch-ac) = cc92318e0979779f6ef03ee653bc94ee2b96a055
-SHA1 (patch-ad) = 8ea70b0501ccd725d19a735699437f67ae76d13d
+SHA1 (patch-ad) = 6155980d095bf56dad6c60fb937d29cd8ea6ffb1
 SHA1 (patch-ae) = 49a01ebe66de4965f3611cf42db09703aa68c415
 SHA1 (patch-af) = e46e576a589fb65488011a41df95f744230c0c6c
 SHA1 (patch-darwin.c) = 20df5d5970bf86f6f4ada002ca16a3bccf5bb4ff
Index: patches/patch-ad
===================================================================
RCS file: /cvsroot/pkgsrc/devel/libusb/patches/patch-ad,v
retrieving revision 1.11
diff -u -r1.11 patch-ad
--- patches/patch-ad	19 Feb 2018 17:59:23 -0000	1.11
+++ patches/patch-ad	23 Jan 2022 18:14:04 -0000
@@ -3,8 +3,8 @@
 Fix build on some platforms.
 Eat EAGAIN returns.
 
---- bsd.c.orig	2006-03-03 18:52:46.000000000 -0800
-+++ bsd.c	2016-10-21 01:20:19.000000000 -0700
+--- bsd.c.orig	2006-03-04 02:52:46.000000000 +0000
++++ bsd.c
 @@ -25,8 +25,8 @@
   * 	for both read and write.
   */
@@ -36,7 +36,7 @@
  /*
   * It appears some of the BSD's (OpenBSD atleast) have switched over to a
   * new naming convention, so we setup some macro's for backward
-@@ -146,7 +150,7 @@
+@@ -146,7 +150,7 @@ int usb_os_open(usb_dev_handle *dev)
      USB_ERROR(-ENOMEM);
    dev->impl_info = info;
  
@@ -45,7 +45,7 @@
    snprintf(ctlpath, PATH_MAX, "%s", dev->device->filename);
  #else
    snprintf(ctlpath, PATH_MAX, "%s.00", dev->device->filename);
-@@ -259,7 +263,7 @@
+@@ -259,7 +263,7 @@ static int ensure_ep_open(usb_dev_handle
    ep = UE_GET_ADDR(ep);
  
    if (info->ep_fd[ep] < 0) {
@@ -54,7 +54,7 @@
      snprintf(buf, sizeof(buf) - 1, "%s.%d", dev->device->filename, ep);
  #else
      snprintf(buf, sizeof(buf) - 1, "%s.%02d", dev->device->filename, ep);
-@@ -290,7 +294,7 @@
+@@ -290,7 +294,7 @@ int usb_bulk_write(usb_dev_handle *dev, 
    fd = ensure_ep_open(dev, ep, O_WRONLY);
    if (fd < 0) {
      if (usb_debug >= 2) {
@@ -63,7 +63,7 @@
        fprintf (stderr, "usb_bulk_write: got negative open file descriptor for endpoint %d\n", UE_GET_ADDR(ep));
  #else
        fprintf (stderr, "usb_bulk_write: got negative open file descriptor for endpoint %02d\n", UE_GET_ADDR(ep));
-@@ -306,7 +310,7 @@
+@@ -306,7 +310,7 @@ int usb_bulk_write(usb_dev_handle *dev, 
  
    ret = write(fd, bytes, size);
    if (ret < 0)
@@ -72,7 +72,7 @@
      USB_ERROR_STR(-errno, "error writing to bulk endpoint %s.%d: %s",
                    dev->device->filename, UE_GET_ADDR(ep), strerror(errno));
  #else
-@@ -328,7 +332,7 @@
+@@ -328,7 +332,7 @@ int usb_bulk_read(usb_dev_handle *dev, i
    fd = ensure_ep_open(dev, ep, O_RDONLY);
    if (fd < 0) {
      if (usb_debug >= 2) {
@@ -81,7 +81,7 @@
        fprintf (stderr, "usb_bulk_read: got negative open file descriptor for endpoint %d\n", UE_GET_ADDR(ep));
  #else
        fprintf (stderr, "usb_bulk_read: got negative open file descriptor for endpoint %02d\n", UE_GET_ADDR(ep));
-@@ -347,7 +351,7 @@
+@@ -347,7 +351,7 @@ int usb_bulk_read(usb_dev_handle *dev, i
  
    ret = read(fd, bytes, size);
    if (ret < 0)
@@ -90,7 +90,16 @@
      USB_ERROR_STR(-errno, "error reading from bulk endpoint %s.%d: %s",
                    dev->device->filename, UE_GET_ADDR(ep), strerror(errno));
  #else
-@@ -369,7 +373,7 @@
+@@ -361,7 +365,7 @@ int usb_bulk_read(usb_dev_handle *dev, i
+ int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size,
+                         int timeout)
+ {
+-  int fd, ret, sent = 0;
++  int fd, ret;
+ 
+   /* Ensure the endpoint address is correct */
+   ep &= ~USB_ENDPOINT_IN;
+@@ -369,7 +373,7 @@ int usb_interrupt_write(usb_dev_handle *
    fd = ensure_ep_open(dev, ep, O_WRONLY);
    if (fd < 0) {
      if (usb_debug >= 2) {
@@ -99,25 +108,44 @@
        fprintf (stderr, "usb_interrupt_write: got negative open file descriptor for endpoint %d\n", UE_GET_ADDR(ep));
  #else
        fprintf (stderr, "usb_interrupt_write: got negative open file descriptor for endpoint %02d\n", UE_GET_ADDR(ep));
-@@ -386,7 +390,7 @@
-   do {
-     ret = write(fd, bytes+sent, size-sent);
-     if (ret < 0)
+@@ -383,27 +387,23 @@ int usb_interrupt_write(usb_dev_handle *
+     USB_ERROR_STR(-errno, "error setting timeout: %s",
+                   strerror(errno));
+ 
+-  do {
+-    ret = write(fd, bytes+sent, size-sent);
+-    if (ret < 0)
 -#ifdef __FreeBSD_kernel__
+-      USB_ERROR_STR(-errno, "error writing to interrupt endpoint %s.%d: %s",
+-                    dev->device->filename, UE_GET_ADDR(ep), strerror(errno));
+-#else
+-      USB_ERROR_STR(-errno, "error writing to interrupt endpoint %s.%02d: %s",
++  ret = write(fd, bytes, size);
++  if (ret < 0)
 +#ifdef FreeBSD_like_device_names
-       USB_ERROR_STR(-errno, "error writing to interrupt endpoint %s.%d: %s",
-                     dev->device->filename, UE_GET_ADDR(ep), strerror(errno));
- #else
-@@ -403,7 +407,7 @@
++    USB_ERROR_STR(-errno, "error writing to interrupt endpoint %s.%d: %s",
+                   dev->device->filename, UE_GET_ADDR(ep), strerror(errno));
++#else
++    USB_ERROR_STR(-errno, "error writing to interrupt endpoint %s.%02d: %s",
++                dev->device->filename, UE_GET_ADDR(ep), strerror(errno));
+ #endif
+ 
+-    sent += ret;
+-  } while (ret > 0 && sent < size);
+-
+-  return sent;
++  return ret;
+ }
+ 
  int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,
                         int timeout)
  {
 -  int fd, ret, retrieved = 0, one = 1;
-+  int fd, ret, retrieved = 0, one = 1, requested;
++  int fd, ret, one = 1;
  
    /* Ensure the endpoint address is correct */
    ep |= USB_ENDPOINT_IN;
-@@ -411,7 +415,7 @@
+@@ -411,7 +411,7 @@ int usb_interrupt_read(usb_dev_handle *d
    fd = ensure_ep_open(dev, ep, O_RDONLY);
    if (fd < 0) {
      if (usb_debug >= 2) {
@@ -126,40 +154,31 @@
        fprintf (stderr, "usb_interrupt_read: got negative open file descriptor for endpoint %d\n", UE_GET_ADDR(ep));
  #else
        fprintf (stderr, "usb_interrupt_read: got negative open file descriptor for endpoint %02d\n", UE_GET_ADDR(ep));
-@@ -429,17 +433,21 @@
+@@ -428,9 +428,8 @@ int usb_interrupt_read(usb_dev_handle *d
+   if (ret < 0)
      USB_ERROR_STR(-errno, "error setting short xfer: %s", strerror(errno));
  
-   do {
+-  do {
 -    ret = read(fd, bytes+retrieved, size-retrieved);
 -    if (ret < 0)
--#ifdef __FreeBSD_kernel__
--      USB_ERROR_STR(-errno, "error reading from interrupt endpoint %s.%d: %s",
--                    dev->device->filename, UE_GET_ADDR(ep), strerror(errno));
--#else
--      USB_ERROR_STR(-errno, "error reading from interrupt endpoint %s.%02d: %s",
--                  dev->device->filename, UE_GET_ADDR(ep), strerror(errno));
--#endif
++  ret = read(fd, bytes, size);
++  if (ret < 0)
+ #ifdef __FreeBSD_kernel__
+       USB_ERROR_STR(-errno, "error reading from interrupt endpoint %s.%d: %s",
+                     dev->device->filename, UE_GET_ADDR(ep), strerror(errno));
+@@ -438,10 +437,8 @@ int usb_interrupt_read(usb_dev_handle *d
+       USB_ERROR_STR(-errno, "error reading from interrupt endpoint %s.%02d: %s",
+                   dev->device->filename, UE_GET_ADDR(ep), strerror(errno));
+ #endif
 -    retrieved += ret;
 -  } while (ret > 0 && retrieved < size);
-+    requested = size - retrieved;
-+    ret = read(fd, bytes+retrieved, requested);
-+    if (ret < 0) {
-+      if (errno != EAGAIN) {
-+#ifdef FreeBSD_like_device_names
-+        USB_ERROR_STR(-errno, "error reading from interrupt endpoint %s.%d: %s",
-+                      dev->device->filename, UE_GET_ADDR(ep), strerror(errno));
-+#else
-+        USB_ERROR_STR(-errno, "error reading from interrupt endpoint %s.%02d: %s",
-+                      dev->device->filename, UE_GET_ADDR(ep), strerror(errno));
-+#endif
-+      }
-+    } else
-+      retrieved += ret;
-+  } while (ret > 0 && retrieved < size && ret != requested);
  
-   return retrieved;
+-  return retrieved;
++  return ret;
  }
-@@ -477,7 +485,7 @@
+ 
+ int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,
+@@ -477,7 +474,7 @@ int usb_control_msg(usb_dev_handle *dev,
      USB_ERROR_STR(-errno, "error sending control message: %s",
                    strerror(errno));
  
@@ -168,7 +187,7 @@
  }
  
  int usb_os_find_busses(struct usb_bus **busses)
-@@ -548,7 +556,7 @@
+@@ -548,7 +545,7 @@ int usb_os_find_devices(struct usb_bus *
        /* best not to play with things we don't understand */
        continue;
  
@@ -177,7 +196,7 @@
      snprintf(buf, sizeof(buf) - 1, "/dev/%s", di.udi_devnames[0]);
  #else
      snprintf(buf, sizeof(buf) - 1, "/dev/%s.00", di.udi_devnames[0]);
-@@ -574,7 +582,7 @@
+@@ -574,7 +571,7 @@ int usb_os_find_devices(struct usb_bus *
      /* we need to report the device name as /dev/ugenx NOT /dev/ugenx.00
       * This seemed easier than having 2 variables...
       */
