examples: Do not assume positive errno macros

Some functions were returning e.g. -ENOMEM and the caller would check
for negative return values. However, on Haiku, contrary to modern
standards, these macros are negative, so this logic would fail. In any
case, change the function to return -1 instead. For good measure also
set errno to the appropriate value, although it is not used in the
current code.

This was discovered on Haiku builds because the value for ENOMEM is
INT_MIN which cannot be negated without overflow.

Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
diff --git a/examples/dpfp.c b/examples/dpfp.c
index a3a76df..6828650 100644
--- a/examples/dpfp.c
+++ b/examples/dpfp.c
@@ -217,7 +217,11 @@
 static int find_dpfp_device(void)
 {
 	devh = libusb_open_device_with_vid_pid(NULL, 0x05ba, 0x000a);
-	return devh ? 0 : -ENODEV;
+	if (!devh) {
+		errno = ENODEV;
+		return -1;
+	}
+	return 0;
 }
 
 static int print_f0_data(void)
@@ -316,13 +320,16 @@
 	unsigned char *buf = malloc(LIBUSB_CONTROL_SETUP_SIZE + 1);
 	struct libusb_transfer *transfer;
 
-	if (!buf)
-		return -ENOMEM;
+	if (!buf) {
+		errno = ENOMEM;
+		return -1;
+	}
 
 	transfer = libusb_alloc_transfer(0);
 	if (!transfer) {
 		free(buf);
-		return -ENOMEM;
+		errno = ENOMEM;
+		return -1;
 	}
 
 	printf("async set mode %02x\n", data);
@@ -547,12 +554,16 @@
 static int alloc_transfers(void)
 {
 	img_transfer = libusb_alloc_transfer(0);
-	if (!img_transfer)
-		return -ENOMEM;
+	if (!img_transfer) {
+		errno = ENOMEM;
+		return -1;
+	}
 
 	irq_transfer = libusb_alloc_transfer(0);
-	if (!irq_transfer)
-		return -ENOMEM;
+	if (!irq_transfer) {
+		errno = ENOMEM;
+		return -1;
+	}
 
 	libusb_fill_bulk_transfer(img_transfer, devh, EP_DATA, imgbuf,
 		sizeof(imgbuf), cb_img, NULL, 0);
diff --git a/examples/ezusb.c b/examples/ezusb.c
index ec60b0e..4bed12a 100644
--- a/examples/ezusb.c
+++ b/examples/ezusb.c
@@ -139,7 +139,11 @@
 		else
 			logerror("%s ==> %d\n", label, status);
 	}
-	return (status < 0) ? -EIO : 0;
+	if (status < 0) {
+		errno = EIO;
+		return -1;
+	}
+	return 0;
 }
 
 /*
@@ -162,7 +166,11 @@
 		else
 			logerror("%s ==> %d\n", label, status);
 	}
-	return (status < 0) ? -EIO : 0;
+	if (status < 0) {
+		errno = EIO;
+		return -1;
+	}
+	return 0;
 }
 
 /*
@@ -514,7 +522,8 @@
 		if (external) {
 			logerror("can't write %u bytes external memory at 0x%08x\n",
 				(unsigned)len, addr);
-			return -EINVAL;
+			errno = EINVAL;
+			return -1;
 		}
 		break;
 	case skip_internal:		/* CPU must be running */
@@ -538,7 +547,8 @@
 	case _undef:
 	default:
 		logerror("bug\n");
-		return -EDOM;
+		errno = EDOM;
+		return -1;
 	}
 
 	ctx->total += len;
diff --git a/examples/sam3u_benchmark.c b/examples/sam3u_benchmark.c
index 33e8913..8979775 100644
--- a/examples/sam3u_benchmark.c
+++ b/examples/sam3u_benchmark.c
@@ -122,8 +122,10 @@
 		num_iso_pack = 16;
 
 	xfr = libusb_alloc_transfer(num_iso_pack);
-	if (!xfr)
-		return -ENOMEM;
+	if (!xfr) {
+		errno = ENOMEM;
+		return -1;
+	}
 
 	if (ep == EP_ISO_IN) {
 		libusb_fill_iso_transfer(xfr, devh, ep, buf,
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 1261c1b..ae20d7d 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11689
+#define LIBUSB_NANO 11690