diff options
| author | Garrett D'Amore <garrett@damore.org> | 2017-01-12 20:46:20 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2017-01-12 21:44:44 -0800 |
| commit | 2bb6a23037656474a90d869c5147b32bae1a2e40 (patch) | |
| tree | 90697aa3fba3186296a18decb32691a1a143b50a /src/platform/windows/win_debug.c | |
| parent | 70348e2d4725c9ec43f51811d290c22c782058ac (diff) | |
| download | nng-2bb6a23037656474a90d869c5147b32bae1a2e40.tar.gz nng-2bb6a23037656474a90d869c5147b32bae1a2e40.tar.bz2 nng-2bb6a23037656474a90d869c5147b32bae1a2e40.zip | |
Initial swag at Win32. Much to do still.
Diffstat (limited to 'src/platform/windows/win_debug.c')
| -rw-r--r-- | src/platform/windows/win_debug.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/platform/windows/win_debug.c b/src/platform/windows/win_debug.c new file mode 100644 index 00000000..189f5d4c --- /dev/null +++ b/src/platform/windows/win_debug.c @@ -0,0 +1,83 @@ +// +// Copyright 2017 Garrett D'Amore <garrett@damore.org> +// +// This software is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +#include "core/nng_impl.h" + +#ifdef PLATFORM_WINDOWS + +#include <errno.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +void +nni_plat_abort(void) +{ + abort(); +} + + +void +nni_plat_println(const char *message) +{ + (void) fprintf(stderr, "%s\n", message); +} + + +const char * +nni_plat_strerror(int errnum) +{ + if (errnum > NNG_ESYSERR) { + errnum -= NNG_ESYSERR; + } + return (strerror(errnum)); +} + + +#define NNI_ERR(x, y) { x, y }, + +// Win32 has its own error codes, but these ones it shares with POSIX. +static struct { + int sys_err; + int nng_err; +} +nni_plat_errnos[] = { + NNI_ERR(ENOENT, NNG_ENOENT) + NNI_ERR(EINTR, NNG_EINTR) + NNI_ERR(EINVAL, NNG_EINVAL) + NNI_ERR(ENOMEM, NNG_ENOMEM) + NNI_ERR(EACCES, NNG_EPERM) + NNI_ERR(EAGAIN, NNG_EAGAIN) + NNI_ERR(EBADF, NNG_ECLOSED) + NNI_ERR(EBUSY, NNG_EBUSY) + NNI_ERR(ENAMETOOLONG, NNG_EINVAL) + NNI_ERR(EPERM, NNG_EPERM) + NNI_ERR(EPIPE, NNG_ECLOSED) + NNI_ERR(0, 0) // must be last +}; + +int +nni_plat_errno(int errnum) +{ + int i; + + if (errnum == 0) { + return (0); + } + for (i = 0; nni_plat_errnos[i].nng_err != 0; i++) { + if (errnum == nni_plat_errnos[i].sys_err) { + return (nni_plat_errnos[i].nng_err); + } + } + // Other system errno. + return (NNG_ESYSERR + errnum); +} + + +#endif // PLATFORM_WINDOWS |
