This source file includes following definitions.
- set_winsock_errno
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <errno.h>
21
22
23 #include <fcntl.h>
24
25
26 #include <io.h>
27
28
29 #if GNULIB_MSVC_NOTHROW
30 # include "msvc-nothrow.h"
31 #else
32 # include <io.h>
33 #endif
34
35 #define FD_TO_SOCKET(fd) ((SOCKET) _get_osfhandle ((fd)))
36 #define SOCKET_TO_FD(fh) (_open_osfhandle ((intptr_t) (fh), O_RDWR | O_BINARY))
37
38 static inline void
39 set_winsock_errno (void)
40 {
41 int err = WSAGetLastError ();
42
43
44 switch (err)
45 {
46 case WSA_INVALID_HANDLE:
47 errno = EBADF;
48 break;
49 case WSA_NOT_ENOUGH_MEMORY:
50 errno = ENOMEM;
51 break;
52 case WSA_INVALID_PARAMETER:
53 errno = EINVAL;
54 break;
55 case WSAENAMETOOLONG:
56 errno = ENAMETOOLONG;
57 break;
58 case WSAENOTEMPTY:
59 errno = ENOTEMPTY;
60 break;
61 case WSAEWOULDBLOCK:
62 errno = EWOULDBLOCK;
63 break;
64 case WSAEINPROGRESS:
65 errno = EINPROGRESS;
66 break;
67 case WSAEALREADY:
68 errno = EALREADY;
69 break;
70 case WSAENOTSOCK:
71 errno = ENOTSOCK;
72 break;
73 case WSAEDESTADDRREQ:
74 errno = EDESTADDRREQ;
75 break;
76 case WSAEMSGSIZE:
77 errno = EMSGSIZE;
78 break;
79 case WSAEPROTOTYPE:
80 errno = EPROTOTYPE;
81 break;
82 case WSAENOPROTOOPT:
83 errno = ENOPROTOOPT;
84 break;
85 case WSAEPROTONOSUPPORT:
86 errno = EPROTONOSUPPORT;
87 break;
88 case WSAEOPNOTSUPP:
89 errno = EOPNOTSUPP;
90 break;
91 case WSAEAFNOSUPPORT:
92 errno = EAFNOSUPPORT;
93 break;
94 case WSAEADDRINUSE:
95 errno = EADDRINUSE;
96 break;
97 case WSAEADDRNOTAVAIL:
98 errno = EADDRNOTAVAIL;
99 break;
100 case WSAENETDOWN:
101 errno = ENETDOWN;
102 break;
103 case WSAENETUNREACH:
104 errno = ENETUNREACH;
105 break;
106 case WSAENETRESET:
107 errno = ENETRESET;
108 break;
109 case WSAECONNABORTED:
110 errno = ECONNABORTED;
111 break;
112 case WSAECONNRESET:
113 errno = ECONNRESET;
114 break;
115 case WSAENOBUFS:
116 errno = ENOBUFS;
117 break;
118 case WSAEISCONN:
119 errno = EISCONN;
120 break;
121 case WSAENOTCONN:
122 errno = ENOTCONN;
123 break;
124 case WSAETIMEDOUT:
125 errno = ETIMEDOUT;
126 break;
127 case WSAECONNREFUSED:
128 errno = ECONNREFUSED;
129 break;
130 case WSAELOOP:
131 errno = ELOOP;
132 break;
133 case WSAEHOSTUNREACH:
134 errno = EHOSTUNREACH;
135 break;
136 default:
137 errno = (err > 10000 && err < 10025) ? err - 10000 : err;
138 break;
139 }
140 }