Re-implement lttng_ust_strerr
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 25 Mar 2021 17:19:34 +0000 (13:19 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 29 Mar 2021 18:00:42 +0000 (14:00 -0400)
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 <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/lttng/ust-error.h
liblttng-ust-comm/lttng-ust-comm.c

index de7e665f27655b5563f6d992503d3fafb92845b9..543c894af92468283deca38bb1e217c9213b2d4a 100644 (file)
@@ -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);
 
index 0b6aa293c696516cbaa5a101dd96a983cad3a151..8141ace369731e3024496f4582e803ebc84c3f9a 100644 (file)
@@ -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)];
 }
 
This page took 0.026007 seconds and 4 git commands to generate.