platform.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. * Plaform 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. #ifdef WINDOWS
  35. #define BREAKPOINT asm("int $3;");
  36. #define GNUNET_SIGCHLD 17
  37. #else
  38. #define BREAKPOINT
  39. #define GNUNET_SIGCHLD SIGCHLD
  40. #endif
  41. #ifdef HAVE_SYS_TYPES_H
  42. #include <sys/types.h>
  43. #endif
  44. /**
  45. * These may be expensive, but good for debugging...
  46. */
  47. #define ALLOW_EXTRA_CHECKS GNUNET_YES
  48. /**
  49. * For strptime (glibc2 needs this).
  50. */
  51. #ifndef _XOPEN_SOURCE
  52. #define _XOPEN_SOURCE 499
  53. #endif
  54. #ifndef _REENTRANT
  55. #define _REENTRANT
  56. #endif
  57. /* configuration options */
  58. #define VERBOSE_STATS 0
  59. #ifdef CYGWIN
  60. #include <sys/reent.h>
  61. #endif
  62. #ifdef _MSC_VER
  63. #ifndef FD_SETSIZE
  64. #define FD_SETSIZE 1024
  65. #endif
  66. #include <Winsock2.h>
  67. #include <ws2tcpip.h>
  68. #else
  69. #ifndef MINGW
  70. #include <netdb.h>
  71. #include <sys/socket.h>
  72. #include <sys/un.h>
  73. #if HAVE_NETINET_IN_H
  74. #include <netinet/in.h>
  75. #endif
  76. #if HAVE_NETINET_IN_SYSTM_H
  77. #include <netinet/in_systm.h>
  78. #endif
  79. #if HAVE_NETINET_IP_H
  80. #include <netinet/ip.h> /* superset of previous */
  81. #endif
  82. #include <arpa/inet.h>
  83. #include <netinet/tcp.h>
  84. #include <pwd.h>
  85. #include <sys/ioctl.h>
  86. #include <sys/wait.h>
  87. #include <grp.h>
  88. #else
  89. #include "winproc.h"
  90. #endif
  91. #endif
  92. #include <string.h>
  93. #include <stdio.h>
  94. #include <stdlib.h>
  95. #include <stdint.h>
  96. #include <stdarg.h>
  97. #include <stdbool.h>
  98. #include <errno.h>
  99. #include <signal.h>
  100. #include <libgen.h>
  101. #ifdef WINDOWS
  102. #include <malloc.h> /* for alloca(), on other OSes it's in stdlib.h */
  103. #endif
  104. #ifdef HAVE_MALLOC_H
  105. #include <malloc.h> /* for mallinfo on GNU */
  106. #endif
  107. #ifndef _MSC_VER
  108. #include <unistd.h> /* KLB_FIX */
  109. #endif
  110. #include <sys/stat.h>
  111. #include <sys/types.h>
  112. #ifndef _MSC_VER
  113. #include <dirent.h> /* KLB_FIX */
  114. #endif
  115. #include <fcntl.h>
  116. #include <math.h>
  117. #if HAVE_SYS_PARAM_H
  118. #include <sys/param.h>
  119. #endif
  120. #if TIME_WITH_SYS_TIME
  121. #include <sys/time.h>
  122. #include <time.h>
  123. #else
  124. #if HAVE_SYS_TIME_H
  125. #include <sys/time.h>
  126. #else
  127. #include <time.h>
  128. #endif
  129. #endif
  130. #ifdef SOMEBSD
  131. #include <net/if.h>
  132. #endif
  133. #ifdef FREEBSD
  134. #include <semaphore.h>
  135. #endif
  136. #ifdef DARWIN
  137. #include <dlfcn.h>
  138. #include <semaphore.h>
  139. #include <net/if.h>
  140. #endif
  141. #if defined(LINUX) || defined(GNU)
  142. #include <net/if.h>
  143. #endif
  144. #ifdef SOLARIS
  145. #include <sys/sockio.h>
  146. #include <sys/filio.h>
  147. #include <sys/loadavg.h>
  148. #include <semaphore.h>
  149. #endif
  150. #if HAVE_UCRED_H
  151. #include <ucred.h>
  152. #endif
  153. #if HAVE_SYS_UCRED_H
  154. #include <sys/ucred.h>
  155. #endif
  156. #ifdef CYGWIN
  157. #include <windows.h>
  158. #include <cygwin/if.h>
  159. #endif
  160. #if HAVE_IFADDRS_H
  161. #include <ifaddrs.h>
  162. #endif
  163. #include <errno.h>
  164. #include <limits.h>
  165. #if HAVE_VFORK_H
  166. #include <vfork.h>
  167. #endif
  168. #include <ctype.h>
  169. #if HAVE_SYS_RESOURCE_H
  170. #include <sys/resource.h>
  171. #endif
  172. #if HAVE_ENDIAN_H
  173. #include <endian.h>
  174. #endif
  175. #if HAVE_SYS_ENDIAN_H
  176. #include <sys/endian.h>
  177. #endif
  178. #include "plibc.h"
  179. #include "compat.h"
  180. #include <locale.h>
  181. #ifndef FRAMEWORK_BUILD
  182. #include "gettext.h"
  183. /**
  184. * GNU gettext support macro.
  185. */
  186. #define _(String) dgettext("gnunet",String)
  187. #define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
  188. #else
  189. #include "libintlemu.h"
  190. #define _(String) dgettext("org.gnunet.gnunet",String)
  191. #define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor"
  192. #endif
  193. #ifdef CYGWIN
  194. #define SIOCGIFCONF _IOW('s', 100, struct ifconf) /* get if list */
  195. #define SIOCGIFFLAGS _IOW('s', 101, struct ifreq) /* Get if flags */
  196. #define SIOCGIFADDR _IOW('s', 102, struct ifreq) /* Get if addr */
  197. #endif
  198. #ifndef MINGW
  199. #include <sys/mman.h>
  200. #endif
  201. #ifdef FREEBSD
  202. #define __BYTE_ORDER BYTE_ORDER
  203. #define __BIG_ENDIAN BIG_ENDIAN
  204. #endif
  205. #ifdef DARWIN
  206. #define __BYTE_ORDER BYTE_ORDER
  207. #define __BIG_ENDIAN BIG_ENDIAN
  208. /* not available on darwin, override configure */
  209. #undef HAVE_STAT64
  210. #undef HAVE_MREMAP
  211. #endif
  212. #if !HAVE_ATOLL
  213. long long
  214. atoll (const char *nptr);
  215. #endif
  216. #if ENABLE_NLS
  217. #include "langinfo.h"
  218. #endif
  219. #ifndef SIZE_MAX
  220. #define SIZE_MAX ((size_t)(-1))
  221. #endif
  222. #ifndef O_LARGEFILE
  223. #define O_LARGEFILE 0
  224. #endif
  225. /**
  226. * AI_NUMERICSERV not defined in windows. Then we just do without.
  227. */
  228. #ifndef AI_NUMERICSERV
  229. #define AI_NUMERICSERV 0
  230. #endif
  231. #if defined(__sparc__)
  232. #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove(&__tmp, &(val), sizeof((val))); __tmp; })
  233. #else
  234. #define MAKE_UNALIGNED(val) val
  235. #endif
  236. #if WINDOWS
  237. #define FDTYPE HANDLE
  238. #define SOCKTYPE SOCKET
  239. #else
  240. #define FDTYPE int
  241. #define SOCKTYPE int
  242. #endif
  243. /**
  244. * The termination signal
  245. */
  246. #define GNUNET_TERM_SIG SIGTERM
  247. #ifndef PATH_MAX
  248. /**
  249. * Assumed maximum path length.
  250. */
  251. #define PATH_MAX 4096
  252. #endif
  253. #if HAVE_THREAD_LOCAL_GCC
  254. #define GNUNET_THREAD_LOCAL __thread
  255. #else
  256. #define GNUNET_THREAD_LOCAL
  257. #endif
  258. #endif