summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2016-12-06 23:11:47 +0100
committerPali Rohár <pali.rohar@gmail.com>2016-12-06 23:11:47 +0100
commit9a5f94004611c901b6914f86721185acd69fc27f (patch)
treea6027ece93b8d9e6f1b2ab860eead82cb48ca98b
parent5e79d651caee6b7a81097ae432b829e3da952261 (diff)
download0xFFFF-9a5f94004611c901b6914f86721185acd69fc27f.tar.bz2
usb-device: Check that we are not using broken libusb-1.0 library
-rw-r--r--src/Makefile2
-rw-r--r--src/usb-device.c9
2 files changed, 10 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile
index 94a8790..6813608 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -11,7 +11,7 @@ HOST_CC = $(HOST_COMPILE)$(CC)
CPPFLAGS += -DVERSION=\"$(VERSION)\" -DBUILD_DATE="\"$(BUILD_DATE)\"" -D_POSIX_C_SOURCE=200809L
CFLAGS += -W -Wall -O2 -pedantic -std=c99
-LIBS += -lusb
+LIBS += -lusb -ldl
DEPENDS = Makefile ../config.mk
diff --git a/src/usb-device.c b/src/usb-device.c
index d3aa707..2913198 100644
--- a/src/usb-device.c
+++ b/src/usb-device.c
@@ -17,6 +17,11 @@
*/
+/* Enable RTLD_DEFAULT for glibc */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -24,6 +29,7 @@
#include <errno.h>
#include <ctype.h>
#include <signal.h>
+#include <dlfcn.h>
#include <usb.h>
@@ -316,6 +322,9 @@ struct usb_device_info * usb_open_and_wait_for_device(void) {
void (*prev)(int);
static char progress[] = {'/','-','\\', '|'};
+ if ( dlsym(RTLD_DEFAULT, "libusb_init") )
+ ERROR_RETURN("You are trying to use broken libusb-1.0 library (either directly or via wrapper) which has slow listing of usb devices. It cannot be used for flashing or cold-flashing. Please use libusb 0.1.", NULL);
+
usb_init();
usb_find_busses();