blob: 69e54254bab1cad85553083e56f470c9eecc9dd9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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();
}
|