X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=error.c;h=e3947a2f6409c0372521d7e024918361be4a1405;hb=a25932e08c6b7424fec07bb2295fadd613294075;hp=1e33d9ab467bc76663362f2b3081133ef4217e3c;hpb=7b870c38e3040fec1165a623ae3986e4fb342218;p=libsigrok.git diff --git a/error.c b/error.c index 1e33d9ab..e3947a2f 100644 --- a/error.c +++ b/error.c @@ -20,11 +20,20 @@ #include "libsigrok.h" +/** + * @file + * + * Error handling in libsigrok. + */ + /** * @defgroup grp_error Error handling * * Error handling in libsigrok. * + * libsigrok functions usually return @ref SR_OK upon success, or a negative + * error code on failure. + * * @{ */ @@ -32,10 +41,14 @@ * 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) { @@ -56,12 +69,18 @@ SR_API const char *sr_strerror(int error_code) case SR_ERR_MALLOC: str = "memory allocation error"; break; + case SR_ERR_ARG: + str = "invalid argument"; + break; case SR_ERR_BUG: str = "internal error"; break; case SR_ERR_SAMPLERATE: str = "invalid samplerate"; break; + case SR_ERR_NA: + str = "not applicable"; + break; default: str = "unknown error"; break; @@ -80,9 +99,13 @@ 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) { @@ -103,12 +126,18 @@ SR_API const char *sr_strerror_name(int error_code) case SR_ERR_MALLOC: str = "SR_ERR_MALLOC"; break; + case SR_ERR_ARG: + str = "SR_ERR_ARG"; + break; case SR_ERR_BUG: str = "SR_ERR_BUG"; break; case SR_ERR_SAMPLERATE: str = "SR_ERR_SAMPLERATE"; break; + case SR_ERR_NA: + str = "SR_ERR_NA"; + break; default: str = "unknown error code"; break;