From ef2cc8b06a71405324cd2d497815f88cff4a0c63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Fri, 7 Nov 2014 23:21:52 +0100
Subject: [PATCH 1/4] Drop unsupported gcc2 flags

---
 configure.ac       | 2 +-
 libusb/Makefile.am | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index debfef2..397098d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -56,7 +56,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], inline_cflags="-fgnu89-inline", inline_
 CFLAGS="$saved_cflags"
 
 AC_DEFINE([API_EXPORTED], [__attribute__((visibility("default")))], [Default visibility])
-AM_CFLAGS="-std=gnu99 $inline_cflags -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration -Wno-pointer-sign -Wshadow"
+AM_CFLAGS="-std=gnu89 $inline_cflags -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration -Wshadow"
 AC_SUBST(AM_CFLAGS)
 
 AC_CONFIG_FILES([libusb.pc] [libusb-config] [Makefile] [libusb/Makefile] [examples/Makefile])
diff --git a/libusb/Makefile.am b/libusb/Makefile.am
index 33a609a..b72849e 100644
--- a/libusb/Makefile.am
+++ b/libusb/Makefile.am
@@ -2,7 +2,7 @@ include_HEADERS = usb.h
 lib_LTLIBRARIES = libusb.la
 
 libusb_la_SOURCES = core.c usbi.h
-libusb_la_CFLAGS = -fvisibility=hidden $(AM_CFLAGS) $(LIBUSB_1_0_CFLAGS)
+libusb_la_CFLAGS = $(AM_CFLAGS) $(LIBUSB_1_0_CFLAGS)
 libusb_la_LIBADD = $(LIBUSB_1_0_LIBS)
 libusb_la_LDFLAGS = -version-info $(LT_MAJOR):$(LT_REVISION):$(LT_AGE) \
 	-release 0.1
-- 
1.8.3.4


From 225917ef9cac34dee263448081cd7db00a9fa45a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Sat, 8 Nov 2014 01:10:41 +0100
Subject: [PATCH 2/4] C89

gcc2 requires C89
---
 libusb/core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libusb/core.c b/libusb/core.c
index c0ccb1f..63567c5 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -210,8 +210,8 @@ static int find_busses(struct usb_bus **ret)
 
 		/* if we already know about it, continue */
 		if (busses) {
-			bus = busses;
 			int found = 0;
+			bus = busses;
 			do {
 				if (bus_num == bus->location) {
 					found = 1;
@@ -661,9 +661,10 @@ API_EXPORTED struct usb_bus *usb_get_busses(void)
 API_EXPORTED usb_dev_handle *usb_open(struct usb_device *dev)
 {
 	int r;
+	usb_dev_handle *udev;
 	usbi_dbg("");
 
-	usb_dev_handle *udev = malloc(sizeof(*udev));
+	udev = malloc(sizeof(*udev));
 	if (!udev)
 		return NULL;
 
-- 
1.8.3.4


From 5afdd1723f5d7cfae10c48a5ede37a42cacad733 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Mon, 11 Aug 2014 19:20:13 +0200
Subject: [PATCH 3/4] Work around ugly return -EFOO constructs

Apps will also need to be fixed...
---
 libusb/core.c | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)

diff --git a/libusb/core.c b/libusb/core.c
index 63567c5..c6fa4bb 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -58,7 +58,12 @@ enum usbi_log_level {
 
 API_EXPORTED struct usb_bus *usb_busses = NULL;
 
-#define compat_err(e) -(errno=libusb_to_errno(e))
+#if (EINVAL < 0)
+#define ret_err(e) (e)
+#else
+#define ret_err(e) -(e)
+#endif
+#define compat_err(e) (ret_err(errno=libusb_to_errno(e)))
 
 static int libusb_to_errno(int result)
 {
@@ -244,7 +249,7 @@ err:
 		free(bus);
 		bus = tbus;
 	}
-	return -ENOMEM;
+	return ret_err(ENOMEM);
 }
 
 API_EXPORTED int usb_find_busses(void)
@@ -352,7 +357,7 @@ err:
 		free(dev);
 		dev = tdev;
 	}
-	return -ENOMEM;
+	return ret_err(ENOMEM);
 }
 
 static void clear_endpoint_descriptor(struct usb_endpoint_descriptor *ep)
@@ -411,7 +416,7 @@ static int copy_endpoint_descriptor(struct usb_endpoint_descriptor *dest,
 	if (src->extra_length) {
 		dest->extra = malloc(src->extra_length);
 		if (!dest->extra)
-			return -ENOMEM;
+			return ret_err(ENOMEM);
 		memcpy(dest->extra, src->extra, src->extra_length);
 	}
 
@@ -428,7 +433,7 @@ static int copy_interface_descriptor(struct usb_interface_descriptor *dest,
 	memcpy(dest, src, USB_DT_INTERFACE_SIZE);
 	dest->endpoint = malloc(alloc_size);
 	if (!dest->endpoint)
-		return -ENOMEM;
+		return ret_err(ENOMEM);
 	memset(dest->endpoint, 0, alloc_size);
 
 	for (i = 0; i < num_endpoints; i++) {
@@ -444,7 +449,7 @@ static int copy_interface_descriptor(struct usb_interface_descriptor *dest,
 		dest->extra = malloc(src->extra_length);
 		if (!dest->extra) {
 			clear_interface_descriptor(dest);
-			return -ENOMEM;
+			return ret_err(ENOMEM);
 		}
 		memcpy(dest->extra, src->extra, src->extra_length);
 	}
@@ -463,7 +468,7 @@ static int copy_interface(struct usb_interface *dest,
 	dest->num_altsetting = num_altsetting;
 	dest->altsetting = malloc(alloc_size);
 	if (!dest->altsetting)
-		return -ENOMEM;
+		return ret_err(ENOMEM);
 	memset(dest->altsetting, 0, alloc_size);
 
 	for (i = 0; i < num_altsetting; i++) {
@@ -488,7 +493,7 @@ static int copy_config_descriptor(struct usb_config_descriptor *dest,
 	memcpy(dest, src, USB_DT_CONFIG_SIZE);
 	dest->interface = malloc(alloc_size);
 	if (!dest->interface)
-		return -ENOMEM;
+		return ret_err(ENOMEM);
 	memset(dest->interface, 0, alloc_size);
 
 	for (i = 0; i < num_interfaces; i++) {
@@ -504,7 +509,7 @@ static int copy_config_descriptor(struct usb_config_descriptor *dest,
 		dest->extra = malloc(src->extra_length);
 		if (!dest->extra) {
 			clear_config_descriptor(dest);
-			return -ENOMEM;
+			return ret_err(ENOMEM);
 		}
 		memcpy(dest->extra, src->extra, src->extra_length);
 	}
@@ -532,7 +537,7 @@ static int initialize_device(struct usb_device *dev)
 	alloc_size = sizeof(struct usb_config_descriptor) * num_configurations;
 	dev->config = malloc(alloc_size);
 	if (!dev->config)
-		return -ENOMEM;
+		return ret_err(ENOMEM);
 	memset(dev->config, 0, alloc_size);
 
 	/* even though structures are identical, we can't just use libusb-1.0's
@@ -734,7 +739,7 @@ API_EXPORTED int usb_set_altinterface(usb_dev_handle *dev, int alternate)
 {
 	usbi_dbg("alternate %d", alternate);
 	if (dev->last_claimed_interface < 0)
-		return -(errno=EINVAL);
+		return ret_err(errno=EINVAL);
 	
 	return compat_err(libusb_set_interface_alt_setting(dev->handle,
 		dev->last_claimed_interface, alternate));
@@ -919,7 +924,7 @@ API_EXPORTED int usb_get_driver_np(usb_dev_handle *dev, int interface,
 		snprintf(name, namelen, "dummy");
 		return 0;
 	} else if (r == 0) {
-		return -(errno=ENODATA);
+		return ret_err(errno=ENODATA);
 	} else {
 		return compat_err(r);
 	}
@@ -932,17 +937,17 @@ API_EXPORTED int usb_detach_kernel_driver_np(usb_dev_handle *dev, int interface)
 	case LIBUSB_SUCCESS:
 		return 0;
 	case LIBUSB_ERROR_NOT_FOUND:
-		return -ENODATA;
+		return ret_err(ENODATA);
 	case LIBUSB_ERROR_INVALID_PARAM:
-		return -EINVAL;
+		return ret_err(EINVAL);
 	case LIBUSB_ERROR_NO_DEVICE:
-		return -ENODEV;
+		return ret_err(ENODEV);
 	case LIBUSB_ERROR_OTHER:
-		return -errno;
+		return ret_err(errno);
 	/* default can be reached only in non-Linux implementations,
 	 * mostly with LIBUSB_ERROR_NOT_SUPPORTED. */
 	default:
-		return -ENOSYS;
+		return ret_err(ENOSYS);
 	}
 }
 
-- 
1.8.3.4


From a625234d9147126e19757fa40a65d97df5f2099d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= <revol@free.fr>
Date: Sun, 9 Nov 2014 01:51:32 +0100
Subject: [PATCH 4/4] Add stdint.h so we get u_int*_t

---
 libusb/usb.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libusb/usb.h b/libusb/usb.h
index 84e730f..a02049b 100644
--- a/libusb/usb.h
+++ b/libusb/usb.h
@@ -26,6 +26,7 @@
 #define __USB_H__
 
 #include <unistd.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <limits.h>
 
-- 
1.8.3.4

