From 2996775898036715b4eb61716094de5ca80e1116 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 27 Jun 2007 19:59:00 +0000 Subject: Minor W32 enhancements --- src/code-from-errno.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src/code-from-errno.c') diff --git a/src/code-from-errno.c b/src/code-from-errno.c index 96fcf20..2895d82 100644 --- a/src/code-from-errno.c +++ b/src/code-from-errno.c @@ -23,11 +23,37 @@ #endif #include +#ifdef HAVE_W32_SYSTEM +#include +#endif #include #include "code-from-errno.h" +#ifdef HAVE_W32_SYSTEM +/* Under Windows socket related error codes are defined in a different + file and prefixed with "WSA". As their ranges don't overlap, we map + some of them to our usual error codes. */ +gpg_err_code_t +w32_special_errnos (int err) +{ + switch (err) + { + case WSAEADDRINUSE: return GPG_ERR_EADDRINUSE; + case WSAEADDRNOTAVAIL: return GPG_ERR_EADDRNOTAVAIL; + case WSAECONNABORTED: return GPG_ERR_ECONNABORTED; + case WSAECONNREFUSED: return GPG_ERR_ECONNREFUSED; + case WSAECONNRESET: return GPG_ERR_ECONNRESET; + case WSAENAMETOOLONG: return GPG_ERR_ENAMETOOLONG; + case WSAEHOSTDOWN: return GPG_ERR_EHOSTDOWN; + case WSAEHOSTUNREACH: return GPG_ERR_EHOSTUNREACH; + default: + return GPG_ERR_UNKNOWN_ERRNO; + } +} +#endif /*HAVE_W32_SYSTEM*/ + /* Retrieve the error code for the system error ERR. This returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report this). */ @@ -42,7 +68,13 @@ gpg_err_code_from_errno (int err) idx = errno_to_idx (err); if (idx < 0) - return GPG_ERR_UNKNOWN_ERRNO; + { +#ifdef HAVE_W32_SYSTEM + return w32_special_errnos (err); +#else + return GPG_ERR_UNKNOWN_ERRNO; +#endif + } return GPG_ERR_SYSTEM_ERROR | err_code_from_index[idx]; } @@ -63,7 +95,13 @@ gpg_err_code_from_syserror (void) idx = errno_to_idx (err); if (idx < 0) - return GPG_ERR_UNKNOWN_ERRNO; + { +#ifdef HAVE_W32_SYSTEM + return w32_special_errnos (err); +#else + return GPG_ERR_UNKNOWN_ERRNO; +#endif + } return GPG_ERR_SYSTEM_ERROR | err_code_from_index[idx]; } -- cgit v1.2.3