]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/errno.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / common / errno.cc
1 #include "common/errno.h"
2 #include "acconfig.h"
3
4 #include <sstream>
5 #include <string>
6
7 #include <string.h>
8
9 std::string cpp_strerror(int err)
10 {
11 char buf[128];
12 char *errmsg;
13
14 if (err < 0)
15 err = -err;
16 std::ostringstream oss;
17 buf[0] = '\0';
18
19 // strerror_r returns char * on Linux, and does not always fill buf
20 #ifdef STRERROR_R_CHAR_P
21 errmsg = strerror_r(err, buf, sizeof(buf));
22 #else
23 strerror_r(err, buf, sizeof(buf));
24 errmsg = buf;
25 #endif
26
27 oss << "(" << err << ") " << errmsg;
28
29 return oss.str();
30 }