Improve error messages relative to libusb calls failures
authorAntonio Ospite <ao2@ao2.it>
Wed, 10 Jun 2015 09:49:31 +0000 (11:49 +0200)
committerAntonio Ospite <ao2@ao2.it>
Wed, 10 Jun 2015 09:49:31 +0000 (11:49 +0200)
src/visomat-data-downloader.c

index 8cb99e2..f93757d 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <errno.h>
 #include <unistd.h>
 #include <libusb.h>
 #include <errno.h>
 #include <unistd.h>
 #include <libusb.h>
@@ -319,7 +320,7 @@ int main(void)
 
        ret = libusb_init(NULL);
        if (ret < 0) {
 
        ret = libusb_init(NULL);
        if (ret < 0) {
-               fprintf(stderr, "error (%d): cannot initialize libusb.\n", ret);
+               fprintf(stderr, "libusb_init failed: %s\n", libusb_error_name(ret));
                goto out;
        }
 
                goto out;
        }
 
@@ -329,15 +330,17 @@ int main(void)
                                              VISOMAT_DEVICE_VID,
                                              VISOMAT_DEVICE_PID);
        if (dev == NULL) {
                                              VISOMAT_DEVICE_VID,
                                              VISOMAT_DEVICE_PID);
        if (dev == NULL) {
-               fprintf(stderr, "error (%d): cannot open device.\n", errno);
+               fprintf(stderr, "libusb_open failed: %s\n", strerror(errno));
                ret = -errno;
                goto out_libusb_exit;
        }
 
        ret = libusb_set_configuration(dev, VISOMAT_CONFIGURATION);
        if (ret < 0) {
                ret = -errno;
                goto out_libusb_exit;
        }
 
        ret = libusb_set_configuration(dev, VISOMAT_CONFIGURATION);
        if (ret < 0) {
-               fprintf(stderr, "error (%d): cannot set configuration %d.\n",
-                       ret, VISOMAT_CONFIGURATION);
+               fprintf(stderr, "libusb_set_configuration failed: %s\n",
+                       libusb_error_name(ret));
+               fprintf(stderr, "Cannot set configuration %hhu\n",
+                       VISOMAT_CONFIGURATION);
                goto out_libusb_close;
        }
 
                goto out_libusb_close;
        }
 
@@ -345,8 +348,10 @@ int main(void)
 
        ret = libusb_claim_interface(dev, VISOMAT_INTERFACE);
        if (ret < 0) {
 
        ret = libusb_claim_interface(dev, VISOMAT_INTERFACE);
        if (ret < 0) {
-               fprintf(stderr, "error (%d): cannot claim interface %d.\n",
-                       ret, VISOMAT_INTERFACE);
+               fprintf(stderr, "libusb_claim_interface failed: %s\n",
+                       libusb_error_name(ret));
+               fprintf(stderr, "Cannot claim interface %hhu\n",
+                       VISOMAT_INTERFACE);
                goto out_libusb_close;
        }
 
                goto out_libusb_close;
        }