| 71 | } // namespace butil |
| 72 | |
| 73 | const char* berror(int error_code) { |
| 74 | if (error_code == -1) { |
| 75 | return "General error -1"; |
| 76 | } |
| 77 | if (error_code >= butil::ERRNO_BEGIN && error_code < butil::ERRNO_END) { |
| 78 | const char* s = butil::errno_desc[error_code - butil::ERRNO_BEGIN]; |
| 79 | if (s) { |
| 80 | return s; |
| 81 | } |
| 82 | #if defined(OS_MACOSX) |
| 83 | const int rc = strerror_r(error_code, butil::tls_error_buf, butil::ERROR_BUFSIZE); |
| 84 | if (rc == 0 || rc == ERANGE/*bufsize is not long enough*/) { |
| 85 | return butil::tls_error_buf; |
| 86 | } |
| 87 | #else |
| 88 | s = strerror_r(error_code, butil::tls_error_buf, butil::ERROR_BUFSIZE); |
| 89 | if (s) { |
| 90 | return s; |
| 91 | } |
| 92 | #endif |
| 93 | } |
| 94 | snprintf(butil::tls_error_buf, butil::ERROR_BUFSIZE, |
| 95 | "Unknown error %d", error_code); |
| 96 | return butil::tls_error_buf; |
| 97 | } |
| 98 | |
| 99 | const char* berror() { |
| 100 | return berror(errno); |