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