fix includes
[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 #if defined(HAVE_WINSOCK2_H) && HAVE_WINSOCK2_H
29 # include <winsock2.h>
30 #endif
31
32 #if defined(HAVE_WS2TCPIP_H) && HAVE_WS2TCPIP_H
33 # include <ws2tcpip.h>
34 #endif
35
36 #if defined(HAVE_IO_H) && HAVE_IO_H
37 # include <io.h>
38 #endif
39
40 struct sockaddr_un {
41 short int sun_family;
42 char sun_path[108];
43 };
44
45 static inline int translate_windows_error() {
46 int local_errno = WSAGetLastError();
47
48 switch (local_errno) {
49 case WSAEINVAL:
50 local_errno = EINPROGRESS;
51 break;
52 case WSAEALREADY:
53 case WSAEWOULDBLOCK:
54 local_errno = EAGAIN;
55 break;
56
57 case WSAECONNREFUSED:
58 local_errno = ECONNREFUSED;
59 break;
60
61 case WSAENETUNREACH:
62 local_errno = ENETUNREACH;
63 break;
64
65 case WSAETIMEDOUT:
66 local_errno = ETIMEDOUT;
67 break;
68
69 case WSAECONNRESET:
70 local_errno = ECONNRESET;
71 break;
72
73 case WSAEADDRINUSE:
74 local_errno = EADDRINUSE;
75 break;
76
77 case WSAEOPNOTSUPP:
78 local_errno = EOPNOTSUPP;
79 break;
80
81 case WSAENOPROTOOPT:
82 local_errno = ENOPROTOOPT;
83 break;
84
85 default:
86 break;
87 }
88
89 return local_errno;
90 }
91
92 static inline char *basename(const char *filename) {
93 static char base[MAX_PATH * 2], ext[MAX_PATH], *ptr;
94 (void) _splitpath_s(filename, NULL, 0, NULL, 0, base, MAX_PATH, ext, MAX_PATH);
95 strcat_s(base, MAX_PATH * 2 - 1, ext);
96 return base;
97 }
98
99 static inline char *realpath(const char *path, char real[MAX_PATH]) {
100 return _fullpath(real, path, MAX_PATH);
101 }