How about returning NO_ERROR for code >= 0 and UNKNOWN_ERROR when code < 0 and doesn't match a defined error
On 09/15/2012 06:31 AM, Hans de Goede wrote: > 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. > > Signed-off-by: Hans de Goede <hdego...@redhat.com> > --- > libusb/core.c | 26 +++++++++++++++++++++----- > libusb/libusb.h | 3 +++ > 2 files changed, 24 insertions(+), 5 deletions(-) > > diff --git a/libusb/core.c b/libusb/core.c > index 3964e3d..097870f 100644 > --- a/libusb/core.c > +++ b/libusb/core.c > @@ -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**"; > } > diff --git a/libusb/libusb.h b/libusb/libusb.h > index ae00c53..b166126 100644 > --- a/libusb/libusb.h > +++ b/libusb/libusb.h > @@ -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 ------------------------------------------------------------------------------ How fast is your code? 3 out of 4 devs don\\\'t know how their code performs in production. Find out how slow your code is with AppDynamics Lite. http://ad.doubleclick.net/clk;262219672;13503038;z? http://info.appdynamics.com/FreeJavaPerformanceDownload.html _______________________________________________ libusbx-devel mailing list libusbx-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libusbx-devel