diff options
author | Werner Koch <wk@gnupg.org> | 2007-06-27 19:59:00 +0000 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2007-06-27 19:59:00 +0000 |
commit | 2996775898036715b4eb61716094de5ca80e1116 (patch) | |
tree | 97fe3186b08b09171fe3976afa7b44a1e0f3dc75 /src/code-from-errno.c | |
parent | 939741c21a1bf76c1f835f298ed38aed1808c867 (diff) | |
download | libgpg-error-2996775898036715b4eb61716094de5ca80e1116.tar.gz |
Minor W32 enhancements
Diffstat (limited to 'src/code-from-errno.c')
-rw-r--r-- | src/code-from-errno.c | 42 |
1 files changed, 40 insertions, 2 deletions
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 <errno.h> +#ifdef HAVE_W32_SYSTEM +#include <winsock2.h> +#endif #include <gpg-error.h> #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]; } |