9#ifdef UA_ARCHITECTURE_WIN32
11#ifndef PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_
12#define PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_
19#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
20# define _CRT_SECURE_NO_WARNINGS
24#if defined(__MINGW32__) && (!defined(WINVER) || WINVER < 0x501)
29# define _WIN32_WINDOWS 0x0600
30# define _WIN32_WINNT 0x0600
34#if defined(_WIN32) && !defined(__clang__)
47#if defined (_MSC_VER) || defined(__clang__)
50# define UA_access _access
54# define UA_access access
57#ifndef _SSIZE_T_DEFINED
61#define OPTVAL_TYPE int
65# define UA_sleep_ms(X) Sleep(X)
73#if defined(__MINGW32__) && !defined(__clang__)
75# define UA_INVALID_SOCKET -1
77# define UA_SOCKET SOCKET
78# define UA_INVALID_SOCKET INVALID_SOCKET
80#define UA_ERRNO WSAGetLastError()
81#define UA_INTERRUPTED WSAEINTR
82#define UA_AGAIN WSAEWOULDBLOCK
83#define UA_EAGAIN EAGAIN
84#define UA_WOULDBLOCK WSAEWOULDBLOCK
85#define UA_ERR_CONNECTION_PROGRESS WSAEWOULDBLOCK
87#define UA_POLLIN POLLRDNORM
88#define UA_POLLOUT POLLWRNORM
90#define UA_fd_set(fd, fds) FD_SET((UA_SOCKET)fd, fds)
91#define UA_fd_isset(fd, fds) FD_ISSET((UA_SOCKET)fd, fds)
97#define UA_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) \
98 getnameinfo(sa, (socklen_t)salen, host, (DWORD)hostlen, serv, (DWORD)servlen, flags)
99#define UA_poll(fds,nfds,timeout) WSAPoll((LPWSAPOLLFD)fds, nfds, timeout)
100#define UA_send(sockfd, buf, len, flags) send(sockfd, buf, (int)(len), flags)
101#define UA_recv(sockfd, buf, len, flags) recv(sockfd, buf, (int)(len), flags)
102#define UA_sendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, (const char*)(buf), (int)(len), flags, dest_addr, (int) (addrlen))
103#define UA_recvfrom(sockfd, buf, len, flags, src_addr, addrlen) recvfrom(sockfd, (char*)(buf), (int)(len), flags, src_addr, addrlen)
105#define UA_htonl htonl
106#define UA_ntohl ntohl
107#define UA_close closesocket
108#define UA_select(nfds, readfds, writefds, exceptfds, timeout) select((int)(nfds), readfds, writefds, exceptfds, timeout)
109#define UA_shutdown shutdown
110#define UA_socket socket
112#define UA_listen listen
113#define UA_accept accept
114#define UA_connect(sockfd, addr, addrlen) connect(sockfd, addr, (int)(addrlen))
115#define UA_getaddrinfo getaddrinfo
116#define UA_getsockopt(sockfd, level, optname, optval, optlen) getsockopt(sockfd, level, optname, (char*) (optval), optlen)
117#define UA_setsockopt(sockfd, level, optname, optval, optlen) setsockopt(sockfd, level, optname, (const char*) (optval), optlen)
119#define UA_freeaddrinfo freeaddrinfo
120#define UA_gethostname gethostname
121#define UA_getsockname getsockname
122#define UA_inet_pton InetPton
125# if defined(__WINCRYPT_H__) && defined(UA_ENABLE_ENCRYPTION_LIBRESSL)
126# error "Wincrypt is not compatible with LibreSSL"
128# ifdef UA_ENABLE_ENCRYPTION_LIBRESSL
130# define __WINCRYPT_H__
133# include <iphlpapi.h>
135# ifdef UA_ENABLE_ENCRYPTION_LIBRESSL
136# undef __WINCRYPT_H__
139# define UA_if_nametoindex if_nametoindex
142#ifdef maxStringLength
143# undef maxStringLength
149# define UA_malloc malloc
150# define UA_calloc calloc
151# define UA_realloc realloc
155#define _snprintf_s(a,b,c,...) snprintf(a,b,__VA_ARGS__)
159#define UA_snprintf(source, size, ...) _snprintf_s(source, size, _TRUNCATE, __VA_ARGS__)
160#define UA_strncasecmp _strnicmp
162#define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
163 char *errno_str = NULL; \
164 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
165 NULL, WSAGetLastError(), \
166 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \
167 (LPSTR)&errno_str, 0, NULL); \
169 LocalFree(errno_str); \
171#define UA_LOG_SOCKET_ERRNO_GAI_WRAP UA_LOG_SOCKET_ERRNO_WRAP
173#if UA_MULTITHREADING >= 100
176 CRITICAL_SECTION mutex;
181UA_LOCK_INIT(UA_Lock *lock) {
182 InitializeCriticalSection(&lock->mutex);
183 lock->mutexCounter = 0;
187UA_LOCK_DESTROY(UA_Lock *lock) {
188 DeleteCriticalSection(&lock->mutex);
192UA_LOCK(UA_Lock *lock) {
193 EnterCriticalSection(&lock->mutex);
198UA_UNLOCK(UA_Lock *lock) {
200 LeaveCriticalSection(&lock->mutex);
204UA_LOCK_ASSERT(UA_Lock *lock,
int num) {
208#define UA_LOCK_INIT(lock)
209#define UA_LOCK_DESTROY(lock)
211#define UA_UNLOCK(lock)
212#define UA_LOCK_ASSERT(lock, num)
218#if !defined(_SYS_QUEUE_H_) && defined(SLIST_ENTRY)
#define UA_assert(ignore)
#define UA_sleep_ms(X)
This work is licensed under a Creative Commons CCZero 1.0 Universal License.