| 16 | #endif |
| 17 | |
| 18 | std::string SysErrorString(int err) |
| 19 | { |
| 20 | char buf[1024]; |
| 21 | /* Too bad there are three incompatible implementations of the |
| 22 | * thread-safe strerror. */ |
| 23 | const char *s = nullptr; |
| 24 | #ifdef WIN32 |
| 25 | if (strerror_s(buf, sizeof(buf), err) == 0) s = buf; |
| 26 | #else |
| 27 | #ifdef STRERROR_R_CHAR_P /* GNU variant can return a pointer outside the passed buffer */ |
| 28 | s = strerror_r(err, buf, sizeof(buf)); |
| 29 | #else /* POSIX variant always returns message in buffer */ |
| 30 | if (strerror_r(err, buf, sizeof(buf)) == 0) s = buf; |
| 31 | #endif |
| 32 | #endif |
| 33 | if (s != nullptr) { |
| 34 | return strprintf("%s (%d)", s, err); |
| 35 | } else { |
| 36 | return strprintf("Unknown error (%d)", err); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | #if defined(WIN32) |
| 41 | std::string Win32ErrorString(int err) |
no outgoing calls
no test coverage detected