From: Michael Jeanson Date: Thu, 25 Mar 2021 17:19:34 +0000 (-0400) Subject: Re-implement lttng_ust_strerr X-Git-Tag: v2.13.0-rc1~189 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d6d2eb792414485fa36c6c473f74235840c678d7;p=lttng-ust.git Re-implement lttng_ust_strerr Re-implement lttng_ust_strerr based on the tools internal implementation. * Require a negative error code from enum lttng_ust_error_code or zero * Don't handle negative error codes as system errors anymore Change-Id: I89a95f4f6b0c392c8fa7bdb3ad40a8d6ea918acf Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/include/lttng/ust-error.h b/include/lttng/ust-error.h index de7e665f..543c894a 100644 --- a/include/lttng/ust-error.h +++ b/include/lttng/ust-error.h @@ -41,8 +41,11 @@ enum lttng_ust_error_code { }; /* - * Return a human-readable error message for an lttng-ust error code. - * code must be a positive value (or 0). + * lttng_ust_strerror + * @code: must be a negative value of enum lttng_ust_error_code (or 0). + * + * Returns a ptr to a string representing a human readable error code from the + * ustcomm_return_code enum. */ const char *lttng_ust_strerror(int code); diff --git a/liblttng-ust-comm/lttng-ust-comm.c b/liblttng-ust-comm/lttng-ust-comm.c index 0b6aa293..8141ace3 100644 --- a/liblttng-ust-comm/lttng-ust-comm.c +++ b/liblttng-ust-comm/lttng-ust-comm.c @@ -70,19 +70,18 @@ static const char *ustcomm_readable_code[] = { /* * lttng_ust_strerror + * @code: must be a negative value of enum lttng_ust_error_code (or 0). * - * Receives positive error value. - * Return ptr to string representing a human readable - * error code from the ustcomm_return_code enum. + * Returns a ptr to a string representing a human readable error code from the + * ustcomm_return_code enum. */ const char *lttng_ust_strerror(int code) { - if (code == LTTNG_UST_OK) - return ustcomm_readable_code[USTCOMM_CODE_OFFSET(code)]; - if (code < LTTNG_UST_ERR) - return strerror(code); - if (code >= LTTNG_UST_ERR_NR) + code = -code; + + if (code < LTTNG_UST_OK || code >= LTTNG_UST_ERR_NR) code = LTTNG_UST_ERR; + return ustcomm_readable_code[USTCOMM_CODE_OFFSET(code)]; }