X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=error.c;h=f87797528088d4e946a5ae884352064843ce7a84;hb=8f54ac8be1768261e113cb15fcdf81013f712674;hp=c9b8589e218991059c3dcc4cd4eeeb6fb4f340e7;hpb=393fb9cb18c5746d8567c9cf74b872804043345a;p=libsigrok.git diff --git a/error.c b/error.c index c9b8589e..f8779752 100644 --- a/error.c +++ b/error.c @@ -1,5 +1,5 @@ /* - * This file is part of the sigrok project. + * This file is part of the libsigrok project. * * Copyright (C) 2012 Uwe Hermann * @@ -41,42 +41,46 @@ * Return a human-readable error string for the given libsigrok error code. * * @param error_code A libsigrok error code number, such as SR_ERR_MALLOC. + * * @return A const string containing a short, human-readable (English) * description of the error, such as "memory allocation error". * The string must NOT be free'd by the caller! + * * @see sr_strerror_name + * + * @since 0.2.0 */ SR_API const char *sr_strerror(int error_code) { - const char *str; - /* - * Note: All defined SR_* error macros from libsigrok.h should have + * Note: All defined SR_* error macros from libsigrok.h must have * an entry in this function, as well as in sr_strerror_name(). */ switch (error_code) { case SR_OK: - str = "no error"; - break; + return "no error"; case SR_ERR: - str = "generic/unspecified error"; - break; + return "generic/unspecified error"; case SR_ERR_MALLOC: - str = "memory allocation error"; - break; + return "memory allocation error"; + case SR_ERR_ARG: + return "invalid argument"; case SR_ERR_BUG: - str = "internal error"; - break; + return "internal error"; case SR_ERR_SAMPLERATE: - str = "invalid samplerate"; - break; + return "invalid samplerate"; + case SR_ERR_NA: + return "not applicable"; + case SR_ERR_DEV_CLOSED: + return "device closed but should be open"; + case SR_ERR_TIMEOUT: + return "timeout occurred"; + case SR_ERR_CHANNEL_GROUP: + return "no channel group specified"; default: - str = "unknown error"; - break; + return "unknown error"; } - - return str; } /** @@ -89,41 +93,45 @@ SR_API const char *sr_strerror(int error_code) * a libsigrok error code is useful. * * @param error_code A libsigrok error code number, such as SR_ERR_MALLOC. + * * @return A const string containing the "name" of the error code as string. * The string must NOT be free'd by the caller! + * * @see sr_strerror + * + * @since 0.2.0 */ SR_API const char *sr_strerror_name(int error_code) { - const char *str; - /* - * Note: All defined SR_* error macros from libsigrok.h should have + * Note: All defined SR_* error macros from libsigrok.h must have * an entry in this function, as well as in sr_strerror(). */ switch (error_code) { case SR_OK: - str = "SR_OK"; - break; + return "SR_OK"; case SR_ERR: - str = "SR_ERR"; - break; + return "SR_ERR"; case SR_ERR_MALLOC: - str = "SR_ERR_MALLOC"; - break; + return "SR_ERR_MALLOC"; + case SR_ERR_ARG: + return "SR_ERR_ARG"; case SR_ERR_BUG: - str = "SR_ERR_BUG"; - break; + return "SR_ERR_BUG"; case SR_ERR_SAMPLERATE: - str = "SR_ERR_SAMPLERATE"; - break; + return "SR_ERR_SAMPLERATE"; + case SR_ERR_NA: + return "SR_ERR_NA"; + case SR_ERR_DEV_CLOSED: + return "SR_ERR_DEV_CLOSED"; + case SR_ERR_TIMEOUT: + return "SR_ERR_TIMEOUT"; + case SR_ERR_CHANNEL_GROUP: + return "SR_ERR_CHANNEL_GROUP"; default: - str = "unknown error code"; - break; + return "unknown error code"; } - - return str; } /** @} */