diff options
Diffstat (limited to 'src/platform/windows/win_debug.c')
| -rw-r--r-- | src/platform/windows/win_debug.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/platform/windows/win_debug.c b/src/platform/windows/win_debug.c index cf8ad9eb..a4edef0d 100644 --- a/src/platform/windows/win_debug.c +++ b/src/platform/windows/win_debug.c @@ -77,6 +77,55 @@ nni_plat_errno(int errnum) return (NNG_ESYSERR + errnum); } +// Windows has infinite numbers of error codes it seems. We only bother +// with the ones that are relevant to us (we think). Note that there is +// no overlap between errnos and GetLastError values. +static struct { + int win_err; + int nng_err; +} +nni_win_errnos[] = { + { ERROR_FILE_NOT_FOUND, NNG_ENOENT }, + { ERROR_ACCESS_DENIED, NNG_EPERM }, + { ERROR_INVALID_HANDLE, NNG_ECLOSED }, + { ERROR_NOT_ENOUGH_MEMORY, NNG_ENOMEM }, + { ERROR_INVALID_ACCESS, NNG_EPERM }, + { ERROR_INVALID_DATA, NNG_EINVAL }, + { ERROR_OUTOFMEMORY, NNG_ENOMEM }, + { ERROR_HANDLE_EOF, NNG_ECLOSED }, + { ERROR_NOT_SUPPORTED, NNG_ENOTSUP }, + { ERROR_OUT_OF_STRUCTURES, NNG_ENOMEM }, + { ERROR_INVALID_PARAMETER, NNG_EINVAL }, + { ERROR_CONNECTION_REFUSED, NNG_ECONNREFUSED }, + { ERROR_BROKEN_PIPE, NNG_ECLOSED }, + { ERROR_BAD_PIPE, NNG_ECLOSED }, + { ERROR_NO_DATA, NNG_ECLOSED }, + { ERROR_PIPE_NOT_CONNECTED, NNG_ECLOSED }, + { ERROR_OPERATION_ABORTED, NNG_ECLOSED }, + { WAIT_TIMEOUT, NNG_ETIMEDOUT }, + // Must be Last!! + { 0, 0 }, +}; + +// This converts a Windows API error (from GetLastError()) to an +// nng standard error code. +int +nni_win_error(int errnum) +{ + int i; + + if (errnum == 0) { + return (0); + } + for (i = 0; nni_win_errnos[i].nng_err != 0; i++) { + if (errnum == nni_win_errnos[i].win_err) { + return (nni_win_errnos[i].nng_err); + } + } + // Other system errno. + return (NNG_ESYSERR + errnum); +} + #else |
