]> err.no Git - yubikey-personalization/commitdiff
Better error handling for libusb-1.0 backend.
authorSimon Josefsson <simon@josefsson.org>
Mon, 10 Aug 2009 08:21:56 +0000 (08:21 +0000)
committerSimon Josefsson <simon@josefsson.org>
Mon, 10 Aug 2009 08:21:56 +0000 (08:21 +0000)
Patch from Tollef Fog Heen <tfheen@err.no>.

ykcore/ykcore_libusb-1.0.c

index ec944f1bf1107dadded883a0666f04263521d971..e7d04e53867b745817b51be5de064ab61f6dc193 100644 (file)
@@ -186,7 +186,50 @@ int _ykusb_close_device(void *yk)
 
 const char *_ykusb_strerror()
 {
-       static char buf[512];
-       snprintf(buf, sizeof(buf), "%s %d", "NOT IMPLEMENTED", ykl_errno);
+       static char *buf;
+       switch (ykl_errno) {
+       case LIBUSB_SUCCESS:
+               buf = "Success (no error)";
+               break;
+       case LIBUSB_ERROR_IO:
+               buf = "Input/output error";
+               break;
+       case LIBUSB_ERROR_INVALID_PARAM:
+               buf = "Invalid parameter";
+               break;
+       case LIBUSB_ERROR_ACCESS:
+               buf = "Access denied (insufficient permissions)";
+               break;
+       case LIBUSB_ERROR_NO_DEVICE:
+               buf = "No such device (it may have been disconnected)";
+               break;
+       case LIBUSB_ERROR_NOT_FOUND:
+               buf = "Entity not found";
+               break;
+       case LIBUSB_ERROR_BUSY:
+               buf = "Resource busy";
+               break;
+       case LIBUSB_ERROR_TIMEOUT:
+               buf = "Operation timed out";
+               break;
+       case LIBUSB_ERROR_OVERFLOW:
+               buf = "Overflow";
+               break;
+       case LIBUSB_ERROR_PIPE:
+               buf = "Pipe error";
+               break;
+       case LIBUSB_ERROR_INTERRUPTED:
+               buf = "System call interrupted (perhaps due to signal)";
+               break;
+       case LIBUSB_ERROR_NO_MEM:
+               buf = "Insufficient memory";
+               break;
+       case LIBUSB_ERROR_NOT_SUPPORTED:
+               buf = "Operation not supported or unimplemented on this platform";
+               break;
+       case LIBUSB_ERROR_OTHER:
+               buf = "Other/unknown error";
+               break;
+       }
        return buf;
 }