platform.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2012 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Nils Durner
  18. * @author Christian Grothoff
  19. *
  20. * @file
  21. * Platform specific includes and defines.
  22. *
  23. * This file should never be included by installed
  24. * header files (those starting with "gnunet_").
  25. */
  26. #ifndef PLATFORM_H
  27. #define PLATFORM_H
  28. #ifndef HAVE_USED_CONFIG_H
  29. #define HAVE_USED_CONFIG_H
  30. #if HAVE_CONFIG_H
  31. #include "gnunet_config.h"
  32. #endif
  33. #endif
  34. #define BREAKPOINT
  35. #define GNUNET_SIGCHLD SIGCHLD
  36. #ifdef HAVE_SYS_TYPES_H
  37. #include <sys/types.h>
  38. #endif
  39. #ifdef __clang__
  40. #undef HAVE_STATIC_ASSERT
  41. #endif
  42. /**
  43. * These may be expensive, but good for debugging...
  44. */
  45. #define ALLOW_EXTRA_CHECKS GNUNET_YES
  46. /**
  47. * For strptime (glibc2 needs this).
  48. */
  49. #ifndef _XOPEN_SOURCE
  50. #define _XOPEN_SOURCE 499
  51. #endif
  52. #ifndef _REENTRANT
  53. #define _REENTRANT
  54. #endif
  55. /* configuration options */
  56. #define VERBOSE_STATS 0
  57. #include <netdb.h>
  58. #include <sys/socket.h>
  59. #include <sys/un.h>
  60. #if HAVE_NETINET_IN_H
  61. #include <netinet/in.h>
  62. #endif
  63. #if HAVE_NETINET_IN_SYSTM_H
  64. #include <netinet/in_systm.h>
  65. #endif
  66. #if HAVE_NETINET_IP_H
  67. #include <netinet/ip.h> /* superset of previous */
  68. #endif
  69. #include <arpa/inet.h>
  70. #include <netinet/tcp.h>
  71. #include <pwd.h>
  72. #include <sys/ioctl.h>
  73. #include <sys/wait.h>
  74. #include <grp.h>
  75. #include <string.h>
  76. #include <stdio.h>
  77. #include <stdlib.h>
  78. #include <stdint.h>
  79. #include <stdarg.h>
  80. #include <stdbool.h>
  81. #include <errno.h>
  82. #include <signal.h>
  83. #include <libgen.h>
  84. #ifdef HAVE_MALLOC_H
  85. #include <malloc.h> /* for mallinfo on GNU */
  86. #endif
  87. #include <unistd.h> /* KLB_FIX */
  88. #include <sys/stat.h>
  89. #include <sys/types.h>
  90. #include <dirent.h> /* KLB_FIX */
  91. #include <fcntl.h>
  92. #include <math.h>
  93. #if HAVE_SYS_PARAM_H
  94. #include <sys/param.h>
  95. #endif
  96. #if TIME_WITH_SYS_TIME
  97. #include <sys/time.h>
  98. #include <time.h>
  99. #else
  100. #if HAVE_SYS_TIME_H
  101. #include <sys/time.h>
  102. #else
  103. #include <time.h>
  104. #endif
  105. #endif
  106. #ifdef BSD
  107. #include <net/if.h>
  108. #endif
  109. #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__)
  110. #include <semaphore.h>
  111. #endif
  112. #ifdef DARWIN
  113. #include <dlfcn.h>
  114. #include <semaphore.h>
  115. #include <net/if.h>
  116. #endif
  117. #if defined(__linux__) || defined(GNU)
  118. #include <net/if.h>
  119. #endif
  120. #ifdef SOLARIS
  121. #include <sys/sockio.h>
  122. #include <sys/filio.h>
  123. #include <sys/loadavg.h>
  124. #include <semaphore.h>
  125. #endif
  126. #if HAVE_UCRED_H
  127. #include <ucred.h>
  128. #endif
  129. #if HAVE_SYS_UCRED_H
  130. #include <sys/ucred.h>
  131. #endif
  132. #if HAVE_IFADDRS_H
  133. #include <ifaddrs.h>
  134. #endif
  135. #include <errno.h>
  136. #include <limits.h>
  137. #if HAVE_VFORK_H
  138. #include <vfork.h>
  139. #endif
  140. #include <ctype.h>
  141. #if HAVE_SYS_RESOURCE_H
  142. #include <sys/resource.h>
  143. #endif
  144. #if HAVE_ENDIAN_H
  145. #include <endian.h>
  146. #endif
  147. #if HAVE_SYS_ENDIAN_H
  148. #include <sys/endian.h>
  149. #endif
  150. #define DIR_SEPARATOR '/'
  151. #define DIR_SEPARATOR_STR "/"
  152. #define PATH_SEPARATOR ':'
  153. #define PATH_SEPARATOR_STR ":"
  154. #define NEWLINE "\n"
  155. #include "compat.h"
  156. #include <locale.h>
  157. #ifndef FRAMEWORK_BUILD
  158. #include "gettext.h"
  159. /**
  160. * GNU gettext support macro.
  161. */
  162. #define _(String) dgettext (PACKAGE, String)
  163. #define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
  164. #else
  165. #include "libintlemu.h"
  166. #define _(String) dgettext ("org.gnunet.gnunet", String)
  167. #define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor"
  168. #endif
  169. #include <sys/mman.h>
  170. /* FreeBSD_kernel is not defined on the now discontinued kFreeBSD */
  171. #if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__)
  172. #define __BYTE_ORDER BYTE_ORDER
  173. #define __BIG_ENDIAN BIG_ENDIAN
  174. #endif
  175. #ifdef DARWIN
  176. #define __BYTE_ORDER BYTE_ORDER
  177. #define __BIG_ENDIAN BIG_ENDIAN
  178. /* not available on darwin, override configure */
  179. #undef HAVE_STAT64
  180. #undef HAVE_MREMAP
  181. #endif
  182. #if ! HAVE_ATOLL
  183. long long
  184. atoll (const char *nptr);
  185. #endif
  186. #if ENABLE_NLS
  187. #include "langinfo.h"
  188. #endif
  189. #ifndef SIZE_MAX
  190. #define SIZE_MAX ((size_t) (-1))
  191. #endif
  192. #ifndef O_LARGEFILE
  193. #define O_LARGEFILE 0
  194. #endif
  195. /**
  196. * AI_NUMERICSERV not defined in windows. Then we just do without.
  197. */
  198. #ifndef AI_NUMERICSERV
  199. #define AI_NUMERICSERV 0
  200. #endif
  201. #if defined(__sparc__)
  202. #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove (&__tmp, &(val), \
  203. sizeof((val))); \
  204. __tmp; })
  205. #else
  206. #define MAKE_UNALIGNED(val) val
  207. #endif
  208. /**
  209. * The termination signal
  210. */
  211. #define GNUNET_TERM_SIG SIGTERM
  212. #ifndef PATH_MAX
  213. /**
  214. * Assumed maximum path length.
  215. */
  216. #define PATH_MAX 4096
  217. #endif
  218. #if HAVE_THREAD_LOCAL_GCC
  219. #define GNUNET_THREAD_LOCAL __thread
  220. #else
  221. #define GNUNET_THREAD_LOCAL
  222. #endif
  223. /**
  224. * clang et al do not have such an attribute
  225. */
  226. #if __has_attribute (__nonstring__)
  227. # define __nonstring __attribute__((__nonstring__))
  228. #else
  229. # define __nonstring
  230. #endif
  231. #endif