Core: Make libusb_error_name also handle transfer status codes
authorHans de Goede <hdegoede@redhat.com>
Sat, 15 Sep 2012 10:31:00 +0000 (11:31 +0100)
committerPete Batard <pete@akeo.ie>
Sat, 15 Sep 2012 22:29:32 +0000 (23:29 +0100)
Note that for the code 0 which means success resp. completed we have an
overlap in the codes. This is not a problem since normally one would not
call libusb_error_name on success / normal completion.

libusb/core.c
libusb/libusb.h
libusb/version_nano.h

index 3964e3d6c424b155ce9fd52ca33688bbec37b715..097870f48d2da1731c54241c309314ab3697e586 100644 (file)
@@ -1881,17 +1881,17 @@ void usbi_log(struct libusb_context *ctx, enum libusb_log_level level,
 
 /** \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.
+ * error or transfer status code. The caller must not free() the returned
+ * string.
  *
- * \param error_code The \ref libusb_error code to return the name of.
+ * \param error_code The \ref libusb_error or libusb_transfer_status 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.
+ * error_code is not a known error / status code.
  */
 DEFAULT_VISIBILITY const char * LIBUSB_CALL libusb_error_name(int error_code)
 {
        switch (error_code) {
-       case LIBUSB_SUCCESS:
-               return "LIBUSB_SUCCESS";
        case LIBUSB_ERROR_IO:
                return "LIBUSB_ERROR_IO";
        case LIBUSB_ERROR_INVALID_PARAM:
@@ -1918,6 +1918,22 @@ DEFAULT_VISIBILITY const char * LIBUSB_CALL libusb_error_name(int error_code)
                return "LIBUSB_ERROR_NOT_SUPPORTED";
        case LIBUSB_ERROR_OTHER:
                return "LIBUSB_ERROR_OTHER";
+
+       case LIBUSB_TRANSFER_ERROR:
+               return "LIBUSB_TRANSFER_ERROR";
+       case LIBUSB_TRANSFER_TIMED_OUT:
+               return "LIBUSB_TRANSFER_TIMED_OUT";
+       case LIBUSB_TRANSFER_CANCELLED:
+               return "LIBUSB_TRANSFER_CANCELLED";
+       case LIBUSB_TRANSFER_STALL:
+               return "LIBUSB_TRANSFER_STALL";
+       case LIBUSB_TRANSFER_NO_DEVICE:
+               return "LIBUSB_TRANSFER_NO_DEVICE";
+       case LIBUSB_TRANSFER_OVERFLOW:
+               return "LIBUSB_TRANSFER_OVERFLOW";
+
+       case 0:
+               return "LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED";
        default:
                return "**UNKNOWN**";
        }
index ae00c53b02e49862503a60122279168298fddabd..b166126b5e14d1fbafc05b516deff9c454fc7762 100644 (file)
@@ -820,6 +820,9 @@ enum libusb_transfer_status {
 
        /** Device sent more data than requested */
        LIBUSB_TRANSFER_OVERFLOW,
+
+       /* NB! Remember to update libusb_error_name()
+          when adding new status codes here. */
 };
 
 /** \ingroup asyncio
index d7392625d7c40eaddaa06aab34995ea05e159ca2..dc44fe4ecb51b455a23d59c3cef596a793f541e2 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10566
+#define LIBUSB_NANO 10567