diff options
author | Paul Fertser <fercerpav@gmail.com> | 2013-05-31 14:57:56 +0400 |
---|---|---|
committer | Spencer Oliver <spen@spen-soft.co.uk> | 2013-06-12 14:40:16 +0000 |
commit | 71ee5f6b5f3172901135640de4ca827b14747465 (patch) | |
tree | 6c7ce79d61ecbeb613c5ff78281238ed1006dcb0 /src/helper | |
parent | 703781c5abaa7e3a93e56e179c2eb4fca53b7550 (diff) |
libusb1_common, ftdi: clarify libusb_open error message
Print a user-friendly message when libusb_open() fails, e.g.
Error: libusb_open() failed with LIBUSB_ERROR_ACCESS
when there's a permissions problem.
Also output a configure warning if libusb older than 1.0.9 is detected.
Change-Id: I800f71f06672fe06c0a98a4e469f853b5021bcfe
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/1430
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Diffstat (limited to 'src/helper')
-rw-r--r-- | src/helper/replacements.c | 42 | ||||
-rw-r--r-- | src/helper/replacements.h | 4 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/helper/replacements.c b/src/helper/replacements.c index 2ae87e55..d8d8fd0b 100644 --- a/src/helper/replacements.c +++ b/src/helper/replacements.c @@ -276,3 +276,45 @@ int win_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct time return retcode; } #endif + +#if defined HAVE_LIBUSB1 && !defined HAVE_LIBUSB_ERROR_NAME +#include <libusb-1.0/libusb.h> +/* Verbatim from git://git.libusb.org/libusb.git tag 1.0.9 + * The libusb_error enum is compatible down to v0.9.1 + */ +const char *libusb_error_name(int error_code) +{ + enum libusb_error error = error_code; + switch (error) { + case LIBUSB_SUCCESS: + return "LIBUSB_SUCCESS"; + case LIBUSB_ERROR_IO: + return "LIBUSB_ERROR_IO"; + case LIBUSB_ERROR_INVALID_PARAM: + return "LIBUSB_ERROR_INVALID_PARAM"; + case LIBUSB_ERROR_ACCESS: + return "LIBUSB_ERROR_ACCESS"; + case LIBUSB_ERROR_NO_DEVICE: + return "LIBUSB_ERROR_NO_DEVICE"; + case LIBUSB_ERROR_NOT_FOUND: + return "LIBUSB_ERROR_NOT_FOUND"; + case LIBUSB_ERROR_BUSY: + return "LIBUSB_ERROR_BUSY"; + case LIBUSB_ERROR_TIMEOUT: + return "LIBUSB_ERROR_TIMEOUT"; + case LIBUSB_ERROR_OVERFLOW: + return "LIBUSB_ERROR_OVERFLOW"; + case LIBUSB_ERROR_PIPE: + return "LIBUSB_ERROR_PIPE"; + case LIBUSB_ERROR_INTERRUPTED: + return "LIBUSB_ERROR_INTERRUPTED"; + case LIBUSB_ERROR_NO_MEM: + return "LIBUSB_ERROR_NO_MEM"; + case LIBUSB_ERROR_NOT_SUPPORTED: + return "LIBUSB_ERROR_NOT_SUPPORTED"; + case LIBUSB_ERROR_OTHER: + return "LIBUSB_ERROR_OTHER"; + } + return "**UNKNOWN**"; +} +#endif diff --git a/src/helper/replacements.h b/src/helper/replacements.h index 0fe93b26..565fe9dc 100644 --- a/src/helper/replacements.h +++ b/src/helper/replacements.h @@ -279,4 +279,8 @@ typedef struct { #endif /* HAVE_ELF_H */ +#if defined HAVE_LIBUSB1 && !defined HAVE_LIBUSB_ERROR_NAME +const char *libusb_error_name(int error_code); +#endif /* defined HAVE_LIBUSB1 && !defined HAVE_LIBUSB_ERROR_NAME */ + #endif /* REPLACEMENTS_H */ |