Quantcast

[PATCH 6/7] libusb_strerror addon

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

[PATCH 6/7] libusb_strerror addon

Pete Batard
NB: this is Francesco Montorsi's patch for libusb_strerror, so not
directly related to the Windows backend, but the xusb test program uses
libusb_strerror, so it is required.

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Libusb-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusb-devel

0006-libusb_strerror-addon.patch (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [PATCH 6/7] libusb_strerror addon

Hans Ulrich Niedermann-3
On Sun, 31 Jan 2010 03:07:00 +0000
Pete Batard <[hidden email]> wrote:

+API_EXPORTED const char* libusb_strerror(enum libusb_error errcode)
+{
+    switch (errcode)
+    {
+        case LIBUSB_SUCCESS:
+            return "Success";
+        case LIBUSB_ERROR_IO:
+            return "Input/output error";

[...]

+        case LIBUSB_ERROR_OTHER:
+            return "Other error";
+
+        default:
+            return "Unknown error";
+    }
+}

I would prefer to structure the libusb_strerror function a little
differently:

API_EXPORTED const char* libusb_strerror(enum libusb_error errcode)
{
    switch (errcode)
    {
        case LIBUSB_SUCCESS:
            return "Success";
        case LIBUSB_ERROR_IO:
            return "Input/output error";

[...]

        case LIBUSB_ERROR_OTHER:
            return "Other error";
    }
    return "Unknown error";
}

This will give the same return value for all input values, but
removing the "default:" label will produce a compiler warning if any
new LIBUSB_ERROR_* code is added to "enum libusb_error" and it has been
forgotten to add a new "case" branch for the new code in the "switch"
statement.

--
Hans Ulrich Niedermann

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Libusb-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusb-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [PATCH 6/7] libusb_strerror addon

Pete Batard
On 2010.01.31 14:20, Hans Ulrich Niedermann wrote:

>          case LIBUSB_ERROR_OTHER:
>              return "Other error";
>      }
>      return "Unknown error";
> }
>
> This will give the same return value for all input values, but
> removing the "default:" label will produce a compiler warning if any
> new LIBUSB_ERROR_* code is added to "enum libusb_error" and it has been
> forgotten to add a new "case" branch for the new code in the "switch"
> statement.
Good thinking. Here's v2 of the patch.

Regards,

/Pete


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Libusb-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusb-devel

0006v2-libusb_strerror-addon.patch (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [PATCH 6/7] libusb_strerror addon

Pete Batard
and here's v3

Regards,

/Pete

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Libusb-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/libusb-devel

0006v3-libusb_strerror-addon.patch (2K) Download Attachment
Loading...