]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #include "common/errno.h" |
2 | #include "acconfig.h" | |
3 | ||
4 | #include <sstream> | |
7c673cae FG |
5 | #include <string.h> |
6 | ||
7 | std::string cpp_strerror(int err) | |
8 | { | |
9 | char buf[128]; | |
10 | char *errmsg; | |
11 | ||
12 | if (err < 0) | |
13 | err = -err; | |
14 | std::ostringstream oss; | |
15 | buf[0] = '\0'; | |
16 | ||
17 | // strerror_r returns char * on Linux, and does not always fill buf | |
18 | #ifdef STRERROR_R_CHAR_P | |
19 | errmsg = strerror_r(err, buf, sizeof(buf)); | |
20 | #else | |
21 | strerror_r(err, buf, sizeof(buf)); | |
22 | errmsg = buf; | |
23 | #endif | |
24 | ||
25 | oss << "(" << err << ") " << errmsg; | |
26 | ||
27 | return oss.str(); | |
28 | } |