ua_architecture.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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_POSIX_UA_ARCHITECTURE_H_
  8. #define PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_
  9. /* Enable POSIX features */
  10. #if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
  11. # define _XOPEN_SOURCE 600
  12. #endif
  13. #ifndef _DEFAULT_SOURCE
  14. # define _DEFAULT_SOURCE
  15. #endif
  16. /* On older systems we need to define _BSD_SOURCE.
  17. * _DEFAULT_SOURCE is an alias for that. */
  18. #ifndef _BSD_SOURCE
  19. # define _BSD_SOURCE
  20. #endif
  21. #include <errno.h>
  22. #include <arpa/inet.h>
  23. #include <netinet/in.h>
  24. #include <netdb.h>
  25. #include <sys/ioctl.h>
  26. #include <sys/select.h>
  27. #define UA_sleep_ms(X) usleep(X * 1000)
  28. #define OPTVAL_TYPE int
  29. #include <fcntl.h>
  30. #include <unistd.h> // read, write, close
  31. #ifdef __QNX__
  32. # include <sys/socket.h>
  33. #endif
  34. #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
  35. # include <sys/param.h>
  36. # if defined(BSD)
  37. # include<sys/socket.h>
  38. # endif
  39. #endif
  40. #if !defined(__CYGWIN__)
  41. # include <netinet/tcp.h>
  42. #endif
  43. /* unsigned int for windows and workaround to a glibc bug */
  44. /* Additionally if GNU_LIBRARY is not defined, it may be using
  45. * musl libc (e.g. Docker Alpine) */
  46. #if defined(__OpenBSD__) || \
  47. (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ <= 6) && \
  48. (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 16) || \
  49. !defined(__GNU_LIBRARY__))
  50. # define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
  51. # define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
  52. #else
  53. # define UA_fd_set(fd, fds) FD_SET(fd, fds)
  54. # define UA_fd_isset(fd, fds) FD_ISSET(fd, fds)
  55. #endif
  56. #define UA_access access
  57. #define UA_IPV6 1
  58. #define UA_SOCKET int
  59. #define UA_INVALID_SOCKET -1
  60. #define UA_ERRNO errno
  61. #define UA_INTERRUPTED EINTR
  62. #define UA_AGAIN EAGAIN
  63. #define UA_EAGAIN EAGAIN
  64. #define UA_WOULDBLOCK EWOULDBLOCK
  65. #define UA_ERR_CONNECTION_PROGRESS EINPROGRESS
  66. #define UA_getnameinfo getnameinfo
  67. #define UA_send send
  68. #define UA_recv recv
  69. #define UA_close close
  70. #define UA_select select
  71. #define UA_shutdown shutdown
  72. #define UA_socket socket
  73. #define UA_bind bind
  74. #define UA_listen listen
  75. #define UA_accept accept
  76. #define UA_connect connect
  77. #define UA_getaddrinfo getaddrinfo
  78. #define UA_getsockopt getsockopt
  79. #define UA_setsockopt setsockopt
  80. #define UA_freeaddrinfo freeaddrinfo
  81. #define UA_gethostname gethostname
  82. #include <stdlib.h>
  83. #define UA_free free
  84. #define UA_malloc malloc
  85. #define UA_calloc calloc
  86. #define UA_realloc realloc
  87. #include <stdio.h>
  88. #define UA_snprintf snprintf
  89. #define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
  90. char *errno_str = strerror(errno); \
  91. LOG; \
  92. }
  93. #define UA_LOG_SOCKET_ERRNO_GAI_WRAP(LOG) { \
  94. const char *errno_str = gai_strerror(errno); \
  95. LOG; \
  96. }
  97. #include "../ua_architecture_functions.h"
  98. #endif /* PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_ */