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 <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/393105
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Daniel Verkamp 2017-12-27 11:03:04 -07:00 committed by Jim Harris
parent 2f700bd9ec
commit 71db3a0870
2 changed files with 12 additions and 7 deletions

View File

@ -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.

View File

@ -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