| 4 | |
| 5 | |
| 6 | std::string errnoToString(int the_errno) |
| 7 | { |
| 8 | const size_t buf_size = 128; |
| 9 | char buf[buf_size]; |
| 10 | |
| 11 | #ifndef _GNU_SOURCE |
| 12 | int rc = strerror_r(the_errno, buf, buf_size); |
| 13 | #ifdef OS_DARWIN |
| 14 | if (rc != 0 && rc != EINVAL) |
| 15 | #else |
| 16 | if (rc != 0) |
| 17 | #endif |
| 18 | { |
| 19 | std::string tmp = std::to_string(the_errno); |
| 20 | const char * code_str = tmp.c_str(); |
| 21 | const char * unknown_message = "Unknown error "; |
| 22 | strcpy(buf, unknown_message); |
| 23 | strcpy(buf + strlen(unknown_message), code_str); |
| 24 | } |
| 25 | return fmt::format("errno: {}, strerror: {}", the_errno, buf); |
| 26 | #else |
| 27 | return fmt::format("errno: {}, strerror: {}", the_errno, strerror_r(the_errno, buf, sizeof(buf))); |
| 28 | #endif |
| 29 | } |