summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Batard <pete@akeo.ie>2014-05-18 19:49:51 +0100
committerPete Batard <pete@akeo.ie>2014-05-18 19:49:51 +0100
commitc0f5e58acb316010015e28104c425cda7e8e1c78 (patch)
treef808a3056d49abc9c6f26ed1edea53a965a63ddc
parentbcc4e517d5ce41e541484ade9b2800ba06a9b903 (diff)
downloadlibusb-c0f5e58acb316010015e28104c425cda7e8e1c78.tar.gz
samples: set xusb to also produce debug output during init when -d is specified
* This can be quite useful for troubleshooting user issues
-rw-r--r--examples/xusb.c23
-rw-r--r--libusb/version_nano.h2
2 files changed, 22 insertions, 3 deletions
diff --git a/examples/xusb.c b/examples/xusb.c
index 540c90e..f7549ca 100644
--- a/examples/xusb.c
+++ b/examples/xusb.c
@@ -33,6 +33,11 @@
#define msleep(msecs) usleep(1000*msecs)
#endif
+#if defined(_MSC_VER)
+#define snprintf _snprintf
+#define putenv _putenv
+#endif
+
#if !defined(bool)
#define bool int
#endif
@@ -973,7 +978,7 @@ int main(int argc, char** argv)
size_t i, arglen;
unsigned tmp_vid, tmp_pid;
uint16_t endian_test = 0xBE00;
- char* error_lang = NULL;
+ char *error_lang = NULL, *old_dbg_str = NULL, str[256];
// Default to generic, expecting VID:PID
VID = 0;
@@ -1089,13 +1094,22 @@ int main(int argc, char** argv)
return 0;
}
+ // xusb is commonly used as a debug tool, so it's convenient to have debug output during libusb_init(),
+ // but since we can't call on libusb_set_debug() before libusb_init(), we use the env variable method
+ old_dbg_str = getenv("LIBUSB_DEBUG");
+ if (debug_mode) {
+ putenv("LIBUSB_DEBUG=4"); // LIBUSB_LOG_LEVEL_DEBUG
+ }
+
version = libusb_get_version();
printf("Using libusb v%d.%d.%d.%d\n\n", version->major, version->minor, version->micro, version->nano);
r = libusb_init(NULL);
if (r < 0)
return r;
- libusb_set_debug(NULL, debug_mode?LIBUSB_LOG_LEVEL_DEBUG:LIBUSB_LOG_LEVEL_INFO);
+ // If not set externally, and no debug option was given, use info log level
+ if ((old_dbg_str == NULL) && (!debug_mode))
+ libusb_set_debug(NULL, LIBUSB_LOG_LEVEL_INFO);
if (error_lang != NULL) {
r = libusb_setlocale(error_lang);
if (r < 0)
@@ -1106,5 +1120,10 @@ int main(int argc, char** argv)
libusb_exit(NULL);
+ if (debug_mode) {
+ snprintf(str, sizeof(str), "LIBUSB_DEBUG=%s", (old_dbg_str == NULL)?"":old_dbg_str);
+ str[sizeof(str) - 1] = 0; // Windows may not NUL terminate the string
+ }
+
return 0;
}
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 350a2d4..94ac72a 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 10888
+#define LIBUSB_NANO 10889