Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Shared uv_strerror
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Nov 10, 2011
1 parent fd2b04d commit 808bb8e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 35 deletions.
21 changes: 0 additions & 21 deletions src/unix/error.c
Expand Up @@ -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
11 changes: 11 additions & 0 deletions src/uv-common.c
Expand Up @@ -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;
Expand Down
14 changes: 0 additions & 14 deletions src/win/error.c
Expand Up @@ -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;
Expand Down

0 comments on commit 808bb8e

Please sign in to comment.