summaryrefslogtreecommitdiffstats
path: root/src/common/errno.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/common/errno.cc
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/common/errno.cc')
-rw-r--r--src/common/errno.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/common/errno.cc b/src/common/errno.cc
new file mode 100644
index 00000000..69e54254
--- /dev/null
+++ b/src/common/errno.cc
@@ -0,0 +1,28 @@
+#include "common/errno.h"
+#include "acconfig.h"
+
+#include <sstream>
+#include <string.h>
+
+std::string cpp_strerror(int err)
+{
+ char buf[128];
+ char *errmsg;
+
+ if (err < 0)
+ err = -err;
+ std::ostringstream oss;
+ buf[0] = '\0';
+
+ // strerror_r returns char * on Linux, and does not always fill buf
+#ifdef STRERROR_R_CHAR_P
+ errmsg = strerror_r(err, buf, sizeof(buf));
+#else
+ strerror_r(err, buf, sizeof(buf));
+ errmsg = buf;
+#endif
+
+ oss << "(" << err << ") " << errmsg;
+
+ return oss.str();
+}