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