platform.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2012 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. 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. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file include/platform.h
  19. * @brief plaform specific includes and defines
  20. * @author Nils Durner
  21. * @author Christian Grothoff
  22. * This file should never be included by installed
  23. * header files (those starting with "gnunet_").
  24. */
  25. #ifndef PLATFORM_H
  26. #define PLATFORM_H
  27. #ifndef HAVE_USED_CONFIG_H
  28. #define HAVE_USED_CONFIG_H
  29. #if HAVE_CONFIG_H
  30. #include "gnunet_config.h"
  31. #endif
  32. #endif
  33. #ifdef WINDOWS
  34. #define BREAKPOINT asm("int $3;");
  35. #define GNUNET_SIGCHLD 17
  36. #else
  37. #define BREAKPOINT
  38. #define GNUNET_SIGCHLD SIGCHLD
  39. #endif
  40. #ifdef HAVE_SYS_TYPES_H
  41. #include <sys/types.h>
  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. #ifdef CYGWIN
  59. #include <sys/reent.h>
  60. #endif
  61. #ifdef _MSC_VER
  62. #ifndef FD_SETSIZE
  63. #define FD_SETSIZE 1024
  64. #endif
  65. #include <Winsock2.h>
  66. #include <ws2tcpip.h>
  67. #else
  68. #ifndef MINGW
  69. #include <netdb.h>
  70. #include <sys/socket.h>
  71. #include <sys/un.h>
  72. #if HAVE_NETINET_IN_H
  73. #include <netinet/in.h>
  74. #endif
  75. #if HAVE_NETINET_IN_SYSTM_H
  76. #include <netinet/in_systm.h>
  77. #endif
  78. #if HAVE_NETINET_IP_H
  79. #include <netinet/ip.h> /* superset of previous */
  80. #endif
  81. #include <arpa/inet.h>
  82. #include <netinet/tcp.h>
  83. #include <pwd.h>
  84. #include <sys/ioctl.h>
  85. #include <sys/wait.h>
  86. #include <grp.h>
  87. #else
  88. #include "winproc.h"
  89. #endif
  90. #endif
  91. #include <string.h>
  92. #include <stdio.h>
  93. #include <stdlib.h>
  94. #include <stdint.h>
  95. #include <stdarg.h>
  96. #include <errno.h>
  97. #include <signal.h>
  98. #include <libgen.h>
  99. #ifdef WINDOWS
  100. #include <malloc.h> /* for alloca(), on other OSes it's in stdlib.h */
  101. #endif
  102. #ifdef HAVE_MALLOC_H
  103. #include <malloc.h> /* for mallinfo on GNU */
  104. #endif
  105. #ifndef _MSC_VER
  106. #include <unistd.h> /* KLB_FIX */
  107. #endif
  108. #include <sys/stat.h>
  109. #include <sys/types.h>
  110. #ifndef _MSC_VER
  111. #include <dirent.h> /* KLB_FIX */
  112. #endif
  113. #include <fcntl.h>
  114. #include <math.h>
  115. #if HAVE_SYS_PARAM_H
  116. #include <sys/param.h>
  117. #endif
  118. #if TIME_WITH_SYS_TIME
  119. #include <sys/time.h>
  120. #include <time.h>
  121. #else
  122. #if HAVE_SYS_TIME_H
  123. #include <sys/time.h>
  124. #else
  125. #include <time.h>
  126. #endif
  127. #endif
  128. #ifdef SOMEBSD
  129. #include <net/if.h>
  130. #endif
  131. #ifdef FREEBSD
  132. #include <semaphore.h>
  133. #endif
  134. #ifdef DARWIN
  135. #include <dlfcn.h>
  136. #include <semaphore.h>
  137. #include <net/if.h>
  138. #endif
  139. #if defined(LINUX) || defined(GNU)
  140. #include <net/if.h>
  141. #endif
  142. #ifdef SOLARIS
  143. #include <sys/sockio.h>
  144. #include <sys/filio.h>
  145. #include <sys/loadavg.h>
  146. #include <semaphore.h>
  147. #endif
  148. #if HAVE_UCRED_H
  149. #include <ucred.h>
  150. #endif
  151. #if HAVE_SYS_UCRED_H
  152. #include <sys/ucred.h>
  153. #endif
  154. #ifdef CYGWIN
  155. #include <windows.h>
  156. #include <cygwin/if.h>
  157. #endif
  158. #if HAVE_IFADDRS_H
  159. #include <ifaddrs.h>
  160. #endif
  161. #include <errno.h>
  162. #include <limits.h>
  163. #if HAVE_VFORK_H
  164. #include <vfork.h>
  165. #endif
  166. #include <ctype.h>
  167. #if HAVE_SYS_RESOURCE_H
  168. #include <sys/resource.h>
  169. #endif
  170. #if HAVE_ENDIAN_H
  171. #include <endian.h>
  172. #endif
  173. #if HAVE_SYS_ENDIAN_H
  174. #include <sys/endian.h>
  175. #endif
  176. #include "plibc.h"
  177. #include <locale.h>
  178. #ifndef FRAMEWORK_BUILD
  179. #include "gettext.h"
  180. /**
  181. * GNU gettext support macro.
  182. */
  183. #define _(String) dgettext("gnunet",String)
  184. #define LIBEXTRACTOR_GETTEXT_DOMAIN "libextractor"
  185. #else
  186. #include "libintlemu.h"
  187. #define _(String) dgettext("org.gnunet.gnunet",String)
  188. #define LIBEXTRACTOR_GETTEXT_DOMAIN "org.gnunet.libextractor"
  189. #endif
  190. #ifdef CYGWIN
  191. #define SIOCGIFCONF _IOW('s', 100, struct ifconf) /* get if list */
  192. #define SIOCGIFFLAGS _IOW('s', 101, struct ifreq) /* Get if flags */
  193. #define SIOCGIFADDR _IOW('s', 102, struct ifreq) /* Get if addr */
  194. #endif
  195. #ifndef MINGW
  196. #include <sys/mman.h>
  197. #endif
  198. #ifdef FREEBSD
  199. #define __BYTE_ORDER BYTE_ORDER
  200. #define __BIG_ENDIAN BIG_ENDIAN
  201. #endif
  202. #ifdef DARWIN
  203. #define __BYTE_ORDER BYTE_ORDER
  204. #define __BIG_ENDIAN BIG_ENDIAN
  205. /* not available on darwin, override configure */
  206. #undef HAVE_STAT64
  207. #undef HAVE_MREMAP
  208. #endif
  209. #if !HAVE_ATOLL
  210. long long
  211. atoll (const char *nptr);
  212. #endif
  213. #if ENABLE_NLS
  214. #include "langinfo.h"
  215. #endif
  216. #ifndef SIZE_MAX
  217. #define SIZE_MAX ((size_t)(-1))
  218. #endif
  219. #ifndef O_LARGEFILE
  220. #define O_LARGEFILE 0
  221. #endif
  222. /**
  223. * AI_NUMERICSERV not defined in windows. Then we just do without.
  224. */
  225. #ifndef AI_NUMERICSERV
  226. #define AI_NUMERICSERV 0
  227. #endif
  228. #if defined(__sparc__)
  229. #define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove(&__tmp, &(val), sizeof((val))); __tmp; })
  230. #else
  231. #define MAKE_UNALIGNED(val) val
  232. #endif
  233. #if WINDOWS
  234. #define FDTYPE HANDLE
  235. #define SOCKTYPE SOCKET
  236. #else
  237. #define FDTYPE int
  238. #define SOCKTYPE int
  239. #endif
  240. /**
  241. * The termination signal
  242. */
  243. #define GNUNET_TERM_SIG SIGTERM
  244. #endif