platform.h 5.6 KB

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