From 4d57f9d92434b88742f826672a4f127d93ad295e Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Wed, 3 Dec 2008 11:34:28 +0000 Subject: [PATCH] win32: errno fixes - switch errors around to correspond to what gets returned - somewhat working strerror() --- win32/compat_win32.h | 11 +++++++---- win32/win32service.c | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/win32/compat_win32.h b/win32/compat_win32.h index d77ef39..87457e5 100644 --- a/win32/compat_win32.h +++ b/win32/compat_win32.h @@ -9,11 +9,11 @@ #include #define ECONNABORTED WSAECONNABORTED -#define EINPROGRESS WSAEINPROGRESS -#define EWOULDBLOCK WSAEWOULDBLOCK +#define EMSGSIZE WSAEMSGSIZE +#define EINPROGRESS WSAEWOULDBLOCK // WSAEINPROGRESS + #undef EAGAIN #define EAGAIN WSAEWOULDBLOCK // WSAEAGAIN -#define EMSGSIZE WSAEMSGSIZE /* dummy types / functions */ #define uid_t int @@ -120,8 +120,11 @@ static inline struct hostent *w_gethostbyname(const char *n) { } #define gethostbyname(a) w_gethostbyname(a) +const char *wsa_strerror(int e); + static inline const char *w_strerror(int e) { - /* wsa does not have its own strerror, maybe main one works */ + if (e > 900) + return wsa_strerror(e); return strerror(e); } #define strerror(x) w_strerror(x) diff --git a/win32/win32service.c b/win32/win32service.c index f14d0b2..5364ff5 100644 --- a/win32/win32service.c +++ b/win32/win32service.c @@ -594,3 +594,22 @@ void syslog(int prio, const char *fmt, ...) void closelog(void) { } + +#define WCASE(x) case x: return #x +const char *wsa_strerror(int e) +{ + static char wsa_buf[256]; + switch (e) { + /* display few common ones by name */ + WCASE(WSAEWOULDBLOCK); + WCASE(WSAEINPROGRESS); + WCASE(WSAECONNABORTED); + WCASE(WSAEINTR); + default: + snprintf(wsa_buf, sizeof(wsa_buf), "wsa_error: %d", e); + return wsa_buf; + } +} +#define strerror(x) w_strerror(x) + + -- 2.40.0