From 157bd362bdab05b0762bba88af766abff422e683 Mon Sep 17 00:00:00 2001 From: "luo.runbing" Date: Thu, 19 Sep 2019 17:30:37 +0800 Subject: [PATCH] common/compat: add strerror_r Signed-off-by: luo.runbing --- src/common/compat.cc | 11 +++++++++++ src/include/compat.h | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/common/compat.cc b/src/common/compat.cc index f681969fff6..bea5dba96e3 100644 --- a/src/common/compat.cc +++ b/src/common/compat.cc @@ -193,3 +193,14 @@ int sched_setaffinity(pid_t pid, size_t cpusetsize, } #endif +char *ceph_strerror_r(int errnum, char *buf, size_t buflen) +{ +#ifdef STRERROR_R_CHAR_P + return strerror_r(errnum, buf, buflen); +#else + if (strerror_r(errnum, buf, buflen)) { + snprintf(buf, buflen, "Unknown error %d", errnum); + } + return buf; +#endif +} diff --git a/src/include/compat.h b/src/include/compat.h index 3b38af54427..bfb12579d69 100644 --- a/src/include/compat.h +++ b/src/include/compat.h @@ -195,4 +195,14 @@ int ceph_posix_fallocate(int fd, off_t offset, off_t len); int pipe_cloexec(int pipefd[2], int flags); +#ifdef __cplusplus +extern "C" { +#endif + +char *ceph_strerror_r(int errnum, char *buf, size_t buflen); + +#ifdef __cplusplus +} +#endif + #endif /* !CEPH_COMPAT_H */ -- 2.39.5