afa0be15f35615c2dc5700a456c820611b7d6684
[m6w6/libmemcached] / src / libmemcached / windows.hpp
1 /*
2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
14 */
15
16 #pragma once
17
18 #ifdef __cplusplus
19 # include <cerrno>
20 #else
21 # include <errno.h>
22 #endif
23
24 #ifndef WIN32_LEAN_AND_MEAN
25 # define WIN32_LEAN_AND_MEAN
26 #endif
27
28 #ifndef _WIN32_WINNT
29 # define _WIN32_WINNT 0x0501
30 #endif
31
32 #ifdef __MINGW32__
33 # if (_WIN32_WINNT >= 0x0501)
34 # else
35 # undef _WIN32_WINNT
36 # define _WIN32_WINNT 0x0501
37 # endif /* _WIN32_WINNT >= 0x0501 */
38 #endif /* __MINGW32__ */
39
40 #if defined(HAVE_WINSOCK2_H) && HAVE_WINSOCK2_H
41 # include <winsock2.h>
42 #endif
43
44 #if defined(HAVE_WS2TCPIP_H) && HAVE_WS2TCPIP_H
45 # include <ws2tcpip.h>
46 #endif
47
48 #if defined(HAVE_IO_H) && HAVE_IO_H
49 # include <io.h>
50 #endif
51
52 struct sockaddr_un {
53 short int sun_family;
54 char sun_path[108];
55 };
56
57 static inline int translate_windows_error() {
58 int local_errno = WSAGetLastError();
59
60 switch (local_errno) {
61 case WSAEINVAL: local_errno = EINPROGRESS; break;
62 case WSAEALREADY:
63 case WSAEWOULDBLOCK: local_errno = EAGAIN; break;
64
65 case WSAECONNREFUSED: local_errno = ECONNREFUSED; break;
66
67 case WSAENETUNREACH: local_errno = ENETUNREACH; break;
68
69 case WSAETIMEDOUT: local_errno = ETIMEDOUT; break;
70
71 case WSAECONNRESET: local_errno = ECONNRESET; break;
72
73 case WSAEADDRINUSE: local_errno = EADDRINUSE; break;
74
75 case WSAEOPNOTSUPP: local_errno = EOPNOTSUPP; break;
76
77 case WSAENOPROTOOPT: local_errno = ENOPROTOOPT; break;
78
79 default: break;
80 }
81
82 return local_errno;
83 }