ua_architecture.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. # include <errno.h>
  26. # include <winsock2.h>
  27. # include <ws2tcpip.h>
  28. # define CLOSESOCKET(S) closesocket((SOCKET)S)
  29. # define ssize_t int
  30. # define WIN32_INT (int)
  31. # define OPTVAL_TYPE char
  32. # define ERR_CONNECTION_PROGRESS WSAEWOULDBLOCK
  33. # define UA_sleep_ms(X) Sleep(X)
  34. /* unsigned int for windows and workaround to a glibc bug */
  35. /* Additionally if GNU_LIBRARY is not defined, it may be using
  36. * musl libc (e.g. Docker Alpine) */
  37. #if defined(_WIN32) || defined(__OpenBSD__) || \
  38. (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ <= 6) && \
  39. (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 16) || \
  40. !defined(__GNU_LIBRARY__))
  41. # define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
  42. # define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
  43. #else
  44. # define UA_fd_set(fd, fds) FD_SET(fd, fds)
  45. # define UA_fd_isset(fd, fds) FD_ISSET(fd, fds)
  46. #endif
  47. #ifdef UNDER_CE
  48. # define errno WSAGetLastError()
  49. #endif
  50. # define errno__ WSAGetLastError()
  51. # define INTERRUPTED WSAEINTR
  52. # define WOULDBLOCK WSAEWOULDBLOCK
  53. # define AGAIN WSAEWOULDBLOCK
  54. #endif /* PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_ */