From 71db3a08703eba6d2f691e68b98297883ec738fc Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 27 Dec 2017 11:03:04 -0700 Subject: [PATCH] util: make spdk_strerror_r() return void Handle the possibility of the system strerror_r() returning an error internally within spdk_strerror_r() so that callers don't need to check the return value. Change-Id: I0571c3f5999873575562d08a04d714716a7881ff Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/393105 Reviewed-by: Pawel Wodkowski Reviewed-by: Ben Walker Tested-by: SPDK Automated Test System Reviewed-by: Dariusz Stojaczyk Reviewed-by: Jim Harris --- include/spdk/string.h | 4 +--- lib/util/string.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/spdk/string.h b/include/spdk/string.h index e86653826..dbb78fd76 100644 --- a/include/spdk/string.h +++ b/include/spdk/string.h @@ -95,10 +95,8 @@ char *spdk_str_trim(char *s); * \param errnum Error code * \param buf Pointer to a buffer in which to place the error message * \param buflen the size of the buffer in bytes - * - * \return 0 upon success, a positive error number or -1 upon failure. */ -int spdk_strerror_r(int errnum, char *buf, size_t buflen); +void spdk_strerror_r(int errnum, char *buf, size_t buflen); /** * Remove trailing newlines from the end of a string in place. diff --git a/lib/util/string.c b/lib/util/string.c index 44a178058..54f2abf9c 100644 --- a/lib/util/string.c +++ b/lib/util/string.c @@ -327,20 +327,27 @@ spdk_str_chomp(char *s) return removed; } -int +void spdk_strerror_r(int errnum, char *buf, size_t buflen) { + int rc; + #if defined(__USE_GNU) char *new_buffer; new_buffer = strerror_r(errnum, buf, buflen); if (new_buffer != NULL) { snprintf(buf, buflen, "%s", new_buffer); - return 0; + rc = 0; + } else { + rc = 1; } - return 0; #else - return strerror_r(errnum, buf, buflen); + rc = strerror_r(errnum, buf, buflen); #endif + + if (rc != 0) { + snprintf(buf, buflen, "Unknown error %d", errnum); + } } int