aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/error.h
blob: 5f2d4cc54761debe23e3e1eca08a1b56859b8af1 (plain) (blame)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#pragma once

#include "defaults.h"

#if defined(_win_)
    #include <winerror.h>
    #include <errno.h>

    #undef E_FAIL
    #undef ERROR_TIMEOUT

    #if defined(_MSC_VER)
        #undef EADDRINUSE
        #undef EADDRNOTAVAIL
        #undef EAFNOSUPPORT
        #undef EALREADY
        #undef ECANCELED
        #undef ECONNABORTED
        #undef ECONNREFUSED
        #undef ECONNRESET
        #undef EDESTADDRREQ
        #undef EHOSTUNREACH
        #undef EINPROGRESS
        #undef EISCONN
        #undef ELOOP
        #undef EMSGSIZE
        #undef ENETDOWN
        #undef ENETRESET
        #undef ENETUNREACH
        #undef ENOBUFS
        #undef ENOPROTOOPT
        #undef ENOTCONN
        #undef ENOTSOCK
        #undef EOPNOTSUPP
        #undef EPROTONOSUPPORT
        #undef EPROTOTYPE
        #undef ETIMEDOUT
        #undef EWOULDBLOCK
        #undef ENAMETOOLONG
        #undef ENOTEMPTY

        #define EWOULDBLOCK WSAEWOULDBLOCK
        #define EINPROGRESS WSAEINPROGRESS
        #define EALREADY WSAEALREADY
        #define ENOTSOCK WSAENOTSOCK
        #define EDESTADDRREQ WSAEDESTADDRREQ
        #define EMSGSIZE WSAEMSGSIZE
        #define EPROTOTYPE WSAEPROTOTYPE
        #define ENOPROTOOPT WSAENOPROTOOPT
        #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
        #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
        #define EOPNOTSUPP WSAEOPNOTSUPP
        #define EPFNOSUPPORT WSAEPFNOSUPPORT
        #define EAFNOSUPPORT WSAEAFNOSUPPORT
        #define EADDRINUSE WSAEADDRINUSE
        #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
        #define ENETDOWN WSAENETDOWN
        #define ENETUNREACH WSAENETUNREACH
        #define ENETRESET WSAENETRESET
        #define ECONNABORTED WSAECONNABORTED
        #define ECONNRESET WSAECONNRESET
        #define ENOBUFS WSAENOBUFS
        #define EISCONN WSAEISCONN
        #define ENOTCONN WSAENOTCONN
        #define ESHUTDOWN WSAESHUTDOWN
        #define ETOOMANYREFS WSAETOOMANYREFS
        #define ETIMEDOUT WSAETIMEDOUT
        #define ECONNREFUSED WSAECONNREFUSED
        #define ELOOP WSAELOOP
        #define ENAMETOOLONG WSAENAMETOOLONG
        #define EHOSTDOWN WSAEHOSTDOWN
        #define EHOSTUNREACH WSAEHOSTUNREACH
        #define ENOTEMPTY WSAENOTEMPTY
        #define EPROCLIM WSAEPROCLIM
        #define EUSERS WSAEUSERS
        #define ESTALE WSAESTALE
        #define EREMOTE WSAEREMOTE
        #define ECANCELED WSAECANCELLED
    #endif

    #define EDQUOT WSAEDQUOT
#endif

void ClearLastSystemError();
int LastSystemError();
void LastSystemErrorText(char* str, size_t size, int code);
const char* LastSystemErrorText(int code);

inline const char* LastSystemErrorText() {
    return LastSystemErrorText(LastSystemError());
}

inline void LastSystemErrorText(char* str, size_t size) {
    LastSystemErrorText(str, size, LastSystemError());
}