From 000c7754915922ab1805131cd7e31eaf21d04a82 Mon Sep 17 00:00:00 2001 From: simon75j Date: Mon, 10 Aug 2009 08:21:56 +0000 Subject: [PATCH] Better error handling for libusb-1.0 backend. Patch from Tollef Fog Heen . git-svn-id: https://yubikey-personalization.googlecode.com/svn/trunk@121 b62f149e-849f-11dd-9899-c7ba65f7c4c7 --- ykcore/ykcore_libusb-1.0.c | 47 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/ykcore/ykcore_libusb-1.0.c b/ykcore/ykcore_libusb-1.0.c index ec944f1..e7d04e5 100644 --- a/ykcore/ykcore_libusb-1.0.c +++ b/ykcore/ykcore_libusb-1.0.c @@ -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; } -- 2.39.5