diff options
author | Peter Stuge <peter@stuge.se> | 2011-09-14 03:00:14 +0200 |
---|---|---|
committer | Peter Stuge <peter@stuge.se> | 2011-10-17 16:25:50 +0200 |
commit | 1b0f758a334d78d3832d17d694ac0c931da36050 (patch) | |
tree | 0da1241850cda23dc9a7d25331760984982c300f /libusb/core.c | |
parent | e16805130a04b2642891e86b8f479e6343ca17da (diff) | |
download | libusbx-1b0f758a334d78d3832d17d694ac0c931da36050.tar.gz |
Add libusb_error_name() API function
Until we have i18ned error messages we can at least offer easy
translation from numeric error code to the error code's name.
[hansg: switch() on enum to get a compiler warning if a case is missing]
[hansg: Better return value when called with an unknown error code]
[hansg: Fix DEFAULT_VISIBILITY in definition to compile on all platforms]
Diffstat (limited to 'libusb/core.c')
-rw-r--r-- | libusb/core.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/libusb/core.c b/libusb/core.c index 0d05333..61083bf 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -1734,3 +1734,47 @@ void usbi_log(struct libusb_context *ctx, enum usbi_log_level level, usbi_log_v(ctx, level, function, format, args); va_end (args); } + +/** \ingroup misc + * Returns a constant NULL-terminated string with the ASCII name of a libusb + * error code. The caller must not free() the returned string. + * + * \param error_code The \ref libusb_error code to return the name of. + * \returns The error name, or the string **UNKNOWN** if the value of + * error_code is not a known error code. + */ +DEFAULT_VISIBILITY const char * LIBUSB_CALL 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**"; +} |