windows.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #ifndef __ZMQ_WINDOWS_HPP_INCLUDED__
4 #define __ZMQ_WINDOWS_HPP_INCLUDED__
5 
6 #ifndef _CRT_SECURE_NO_WARNINGS
7 #define _CRT_SECURE_NO_WARNINGS
8 #endif
9 #ifndef NOMINMAX
10 #define NOMINMAX // Macros min(a,b) and max(a,b)
11 #endif
12 
13 // Set target version to Windows Server 2008, Windows Vista or higher.
14 // Windows XP (0x0501) is supported but without client & server socket types.
15 #if !defined _WIN32_WINNT && !defined ZMQ_HAVE_WINDOWS_UWP
16 #define _WIN32_WINNT 0x0600
17 #endif
18 
19 #ifdef __MINGW32__
20 // Require Windows XP or higher with MinGW for getaddrinfo().
21 #if (_WIN32_WINNT >= 0x0501)
22 #else
23 #error You need at least Windows XP target
24 #endif
25 #endif
26 
27 #include <winsock2.h>
28 #include <windows.h>
29 #include <mswsock.h>
30 #include <iphlpapi.h>
31 #include <string>
32 #include <vector>
33 
34 #if !defined __MINGW32__
35 #include <mstcpip.h>
36 #endif
37 
38 // Workaround missing mstcpip.h in mingw32 (MinGW64 provides this)
39 // __MINGW64_VERSION_MAJOR is only defined when using in mingw-w64
40 #if defined __MINGW32__ && !defined SIO_KEEPALIVE_VALS \
41  && !defined __MINGW64_VERSION_MAJOR
42 struct tcp_keepalive
43 {
44  u_long onoff;
45  u_long keepalivetime;
46  u_long keepaliveinterval;
47 };
48 #define SIO_KEEPALIVE_VALS _WSAIOW (IOC_VENDOR, 4)
49 #endif
50 
51 #include <ws2tcpip.h>
52 #include <ipexport.h>
53 #if !defined _WIN32_WCE
54 #include <process.h>
55 #endif
56 
57 #if defined ZMQ_IOTHREAD_POLLER_USE_POLL || defined ZMQ_POLL_BASED_ON_POLL
58 static inline int poll (struct pollfd *pfd, unsigned long nfds, int timeout)
59 {
60  return WSAPoll (pfd, nfds, timeout);
61 }
62 #endif
63 
64 // In MinGW environment AI_NUMERICSERV is not defined.
65 #ifndef AI_NUMERICSERV
66 #define AI_NUMERICSERV 0x0400
67 #endif
68 
69 // Need unlink() and rmdir() functions that take utf-8 encoded file path.
70 static inline std::wstring utf8_to_utf16 (const char *utf8_string)
71 {
72  std::wstring retVal;
73 
74  if (utf8_string && *utf8_string) {
75  const int utf16_length = ::MultiByteToWideChar (
76  CP_UTF8, MB_ERR_INVALID_CHARS, utf8_string,
77  -1, // assume the input string is null-terminated
78  NULL, 0);
79 
80  if (utf16_length > 0) {
81  retVal.resize (utf16_length);
82 
83  const int conversion_result = ::MultiByteToWideChar (
84  CP_UTF8, MB_ERR_INVALID_CHARS, utf8_string,
85  -1, // assume the input string is null-terminated
86  &retVal[0], static_cast<int> (retVal.size ()));
87 
88  if (conversion_result == 0)
89  retVal.clear ();
90  }
91  }
92 
93  return retVal;
94 }
95 
96 static inline int unlink_utf8 (const char *filename)
97 {
98  return _wunlink (utf8_to_utf16 (filename).c_str ());
99 }
100 
101 static inline int rmdir_utf8 (const char *filename)
102 {
103  return _wrmdir (utf8_to_utf16 (filename).c_str ());
104 }
105 
106 // In MSVC prior to v14, snprintf is not available
107 // The closest implementation is the _snprintf_s function
108 #if defined(_MSC_VER) && _MSC_VER < 1900
109 #define snprintf(buffer_, count_, format_, ...) \
110  _snprintf_s (buffer_, count_, _TRUNCATE, format_, __VA_ARGS__)
111 #endif
112 
113 // Workaround missing struct sockaddr_un in afunix.h.
114 // Fix #3949.
115 #if defined(ZMQ_HAVE_IPC) && !defined(ZMQ_HAVE_STRUCT_SOCKADDR_UN)
116 struct sockaddr_un
117 {
118  ADDRESS_FAMILY sun_family; /* AF_UNIX */
119  char sun_path[108]; /* pathname */
120 };
121 #endif
122 
123 #endif
rmdir_utf8
static int rmdir_utf8(const char *filename)
Definition: windows.hpp:101
NULL
NULL
Definition: test_security_zap.cpp:405
unlink_utf8
static int unlink_utf8(const char *filename)
Definition: windows.hpp:96
testing::internal::wstring
::std::wstring wstring
Definition: gtest-port.h:887
zmq::detail::poll
int poll(zmq_pollitem_t *items_, size_t nitems_, long timeout_)
Definition: zmq.hpp:306
timeout
GLbitfield GLuint64 timeout
Definition: glcorearb.h:3588
utf8_to_utf16
static std::wstring utf8_to_utf16(const char *utf8_string)
Definition: windows.hpp:70


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:07:01