Shared uv_strerror

This commit is contained in:
Ryan Dahl 2011-11-09 18:06:49 -08:00
parent fd2b04d784
commit 808bb8ed0b
3 changed files with 11 additions and 35 deletions

View File

@ -120,24 +120,3 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
assert(0 && "unreachable");
return -1;
}
/* TODO Pull in error messages so we don't have to
* a) rely on what the system provides us
* b) reverse-map the error codes
*/
#define UV_STRERROR_GEN(val, name, s) case UV_##name : return s;
const char* uv_strerror(uv_err_t err) {
int errorno;
if (err.code == UV_EADDRINFO) {
return gai_strerror(errorno);
}
switch (err.code) {
UV_ERRNO_MAP(UV_STRERROR_GEN)
default:
return strerror(err.sys_errno_);
}
}
#undef UV_STRERROR_GEN

View File

@ -62,6 +62,17 @@ const char* uv_err_name(uv_err_t err) {
#undef UV_ERR_NAME_GEN
#define UV_STRERROR_GEN(val, name, s) case UV_##name : return s;
const char* uv_strerror(uv_err_t err) {
switch (err.code) {
UV_ERRNO_MAP(UV_STRERROR_GEN)
default:
return "Unknown system error";
}
}
#undef UV_STRERROR_GEN
void uv__set_error(uv_loop_t* loop, uv_err_code code, int sys_error) {
loop->last_err.code = code;
loop->last_err.sys_errno_ = sys_error;

View File

@ -64,20 +64,6 @@ void uv_fatal_error(const int errorno, const char* syscall) {
}
/* TODO: thread safety */
static char* last_err_str_ = NULL;
#define UV_STRERROR_GEN(val, name, s) case UV_##name : return s;
const char* uv_strerror(uv_err_t err) {
switch (err.code) {
UV_ERRNO_MAP(UV_STRERROR_GEN)
default:
return "Unknown system error";
}
}
#undef UV_STRERROR_GEN
uv_err_code uv_translate_sys_error(int sys_errno) {
switch (sys_errno) {
case ERROR_SUCCESS: return UV_OK;