aboutsummaryrefslogtreecommitdiff
path: root/src/platform/windows/win_debug.c
blob: 00fd64938b91501cc23d40b4a7ec7838ff2f83a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// 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));
}


// Win32 has its own error codes, but these ones it shares with POSIX.
static struct {
	int	sys_err;
	int	nng_err;
}
nni_plat_errnos[] = {
	{ ENOENT,	NNG_ENOENT  },
	{ EINTR,	NNG_EINTR   },
	{ EINVAL,	NNG_EINVAL  },
	{ ENOMEM,	NNG_ENOMEM  },
	{ EACCES,	NNG_EPERM   },
	{ EAGAIN,	NNG_EAGAIN  },
	{ EBADF,	NNG_ECLOSED },
	{ EBUSY,	NNG_EBUSY   },
	{ ENAMETOOLONG, NNG_EINVAL  },
	{ EPERM,	NNG_EPERM   },
	{ EPIPE,	NNG_ECLOSED },
	{	     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