ua_architecture.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  3. *
  4. * Copyright 2016-2017 (c) Julius Pfrommer, Fraunhofer IOSB
  5. * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
  6. */
  7. #ifndef PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_
  8. #define PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_
  9. #ifndef _BSD_SOURCE
  10. # define _BSD_SOURCE
  11. #endif
  12. /* Disable some security warnings on MSVC */
  13. #ifdef _MSC_VER
  14. # define _CRT_SECURE_NO_WARNINGS
  15. #endif
  16. /* Assume that Windows versions are newer than Windows XP */
  17. #if defined(__MINGW32__) && (!defined(WINVER) || WINVER < 0x501)
  18. # undef WINVER
  19. # undef _WIN32_WINDOWS
  20. # undef _WIN32_WINNT
  21. # define WINVER 0x0501
  22. # define _WIN32_WINDOWS 0x0501
  23. # define _WIN32_WINNT 0x0501
  24. #endif
  25. /* Backup definition of SLIST_ENTRY on mingw winnt.h */
  26. #ifdef SLIST_ENTRY
  27. # pragma push_macro("SLIST_ENTRY")
  28. # undef SLIST_ENTRY
  29. # define POP_SLIST_ENTRY
  30. #endif
  31. #include <stdlib.h>
  32. #if defined(_WIN32) && !defined(__clang__)
  33. # include <malloc.h>
  34. #endif
  35. #include <stdio.h>
  36. #include <errno.h>
  37. #include <winsock2.h>
  38. #include <ws2tcpip.h>
  39. #include <windows.h>
  40. #ifdef _MSC_VER
  41. # ifndef UNDER_CE
  42. # include <io.h> //access
  43. # define UA_access _access
  44. # endif
  45. #else
  46. # include <unistd.h> //access and tests
  47. # define UA_access access
  48. #endif
  49. #ifdef POP_SLIST_ENTRY
  50. # undef SLIST_ENTRY
  51. # undef POP_SLIST_ENTRY
  52. # pragma pop_macro("SLIST_ENTRY")
  53. #endif
  54. #define ssize_t int
  55. #define OPTVAL_TYPE char
  56. #define UA_sleep_ms(X) Sleep(X)
  57. #define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
  58. #define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
  59. #ifdef UNDER_CE
  60. # define errno
  61. #endif
  62. #define UA_IPV6 1
  63. #define UA_SOCKET int
  64. #define UA_INVALID_SOCKET -1
  65. #define UA_ERRNO WSAGetLastError()
  66. #define UA_INTERRUPTED WSAEINTR
  67. #define UA_AGAIN WSAEWOULDBLOCK
  68. #define UA_EAGAIN EAGAIN
  69. #define UA_WOULDBLOCK WSAEWOULDBLOCK
  70. #define UA_ERR_CONNECTION_PROGRESS WSAEWOULDBLOCK
  71. #define UA_getnameinfo getnameinfo
  72. #define UA_send send
  73. #define UA_recv recv
  74. #define UA_close closesocket
  75. #define UA_select select
  76. #define UA_shutdown shutdown
  77. #define UA_socket socket
  78. #define UA_bind bind
  79. #define UA_listen listen
  80. #define UA_accept accept
  81. #define UA_connect connect
  82. #define UA_getaddrinfo getaddrinfo
  83. #define UA_getsockopt getsockopt
  84. #define UA_setsockopt setsockopt
  85. #define UA_freeaddrinfo freeaddrinfo
  86. #define UA_gethostname gethostname
  87. #define UA_free free
  88. #define UA_malloc malloc
  89. #define UA_calloc calloc
  90. #define UA_realloc realloc
  91. #define UA_snprintf(source, size, string, ...) _snprintf_s(source, size, _TRUNCATE, string, __VA_ARGS__)
  92. #define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
  93. char *errno_str = NULL; \
  94. FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
  95. NULL, WSAGetLastError(), \
  96. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \
  97. (LPSTR)&errno_str, 0, NULL); \
  98. LOG; \
  99. LocalFree(errno_str); \
  100. }
  101. #define UA_LOG_SOCKET_ERRNO_GAI_WRAP UA_LOG_SOCKET_ERRNO_WRAP
  102. #include "../ua_architecture_functions.h"
  103. #endif /* PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_ */