setup.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. #ifndef __LIB_CURL_SETUP_H
  2. #define __LIB_CURL_SETUP_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2008, Daniel Stenberg, <[email protected]>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at http://curl.haxx.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * $Id$
  24. ***************************************************************************/
  25. /*
  26. * Define WIN32 when build target is Win32 API
  27. */
  28. #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) && !defined(__SYMBIAN32__)
  29. #define WIN32
  30. #endif
  31. /*
  32. * Include configuration script results or hand-crafted
  33. * configuration file for platforms which lack config tool.
  34. */
  35. #ifdef HAVE_CONFIG_H
  36. #include "config.h"
  37. #else
  38. #ifdef _WIN32_WCE
  39. #include "config-win32ce.h"
  40. #else
  41. #ifdef WIN32
  42. #include "config-win32.h"
  43. #endif
  44. #endif
  45. #ifdef macintosh
  46. #include "config-mac.h"
  47. #endif
  48. #ifdef __AMIGA__
  49. #include "amigaos.h"
  50. #endif
  51. #ifdef __SYMBIAN32__
  52. #include "config-symbian.h"
  53. #endif
  54. #ifdef __OS400__
  55. # include "config-os400.h"
  56. #endif
  57. #ifdef TPF
  58. #include "config-tpf.h" /* hand-modified TPF config.h */
  59. /* change which select is used for libcurl */
  60. #define select(a,b,c,d,e) tpf_select_libcurl(a,b,c,d,e)
  61. #endif
  62. #endif /* HAVE_CONFIG_H */
  63. /* ================================================================ */
  64. /* Definition of preprocessor macros/symbols which modify compiler */
  65. /* behaviour or generated code characteristics must be done here, */
  66. /* as appropriate, before any system header file is included. It is */
  67. /* also possible to have them defined in the config file included */
  68. /* before this point. As a result of all this we frown inclusion of */
  69. /* system header files in our config files, avoid this at any cost. */
  70. /* ================================================================ */
  71. /*
  72. * Tru64 needs _REENTRANT set for a few function prototypes and
  73. * things to appear in the system header files. Unixware needs it
  74. * to build proper reentrant code. Others may also need it.
  75. */
  76. #ifdef NEED_REENTRANT
  77. # ifndef _REENTRANT
  78. # define _REENTRANT
  79. # endif
  80. #endif
  81. /* ================================================================ */
  82. /* If you need to include a system header file for your platform, */
  83. /* please, do it beyond the point further indicated in this file. */
  84. /* ================================================================ */
  85. /*
  86. * libcurl's external interface definitions are also used internally,
  87. * and might also include required system header files to define them.
  88. */
  89. #include <curl/curlbuild.h>
  90. /*
  91. * Compile time sanity checks must also be done when building the library.
  92. */
  93. #include <curl/curlrules.h>
  94. /*
  95. * Ensure that no one is using the old SIZEOF_CURL_OFF_T macro
  96. */
  97. #ifdef SIZEOF_CURL_OFF_T
  98. # error "SIZEOF_CURL_OFF_T shall not be defined!"
  99. Error Compilation_aborted_SIZEOF_CURL_OFF_T_shall_not_be_defined
  100. #endif
  101. /*
  102. * Set up internal curl_off_t formatting string directives for
  103. * exclusive use with libcurl's internal *printf functions.
  104. */
  105. #ifdef FORMAT_OFF_T
  106. # error "FORMAT_OFF_T shall not be defined before this point!"
  107. Error Compilation_aborted_FORMAT_OFF_T_already_defined
  108. #endif
  109. #ifdef FORMAT_OFF_TU
  110. # error "FORMAT_OFF_TU shall not be defined before this point!"
  111. Error Compilation_aborted_FORMAT_OFF_TU_already_defined
  112. #endif
  113. #if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
  114. # define FORMAT_OFF_T "lld"
  115. # define FORMAT_OFF_TU "llu"
  116. #else
  117. # define FORMAT_OFF_T "ld"
  118. # define FORMAT_OFF_TU "lu"
  119. #endif
  120. /*
  121. * Disable other protocols when http is the only one desired.
  122. */
  123. #ifdef HTTP_ONLY
  124. # define CURL_DISABLE_TFTP
  125. # define CURL_DISABLE_FTP
  126. # define CURL_DISABLE_LDAP
  127. # define CURL_DISABLE_TELNET
  128. # define CURL_DISABLE_DICT
  129. # define CURL_DISABLE_FILE
  130. #endif
  131. /* ================================================================ */
  132. /* No system header file shall be included in this file before this */
  133. /* point. The only allowed ones are those included from curlbuild.h */
  134. /* ================================================================ */
  135. /*
  136. * OS/400 setup file includes some system headers.
  137. */
  138. #ifdef __OS400__
  139. # include "setup-os400.h"
  140. #endif
  141. /*
  142. * Include header files for windows builds before redefining anything.
  143. * Use this preproessor block only to include or exclude windows.h,
  144. * winsock2.h, ws2tcpip.h or winsock.h. Any other windows thing belongs
  145. * to any other further and independant block. Under Cygwin things work
  146. * just as under linux (e.g. <sys/socket.h>) and the winsock headers should
  147. * never be included when __CYGWIN__ is defined. configure script takes
  148. * care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK_H, HAVE_WINSOCK2_H,
  149. * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined.
  150. */
  151. #ifdef HAVE_WINDOWS_H
  152. # ifndef WIN32_LEAN_AND_MEAN
  153. # define WIN32_LEAN_AND_MEAN
  154. # endif
  155. # include <windows.h>
  156. # ifdef HAVE_WINSOCK2_H
  157. # include <winsock2.h>
  158. # ifdef HAVE_WS2TCPIP_H
  159. # include <ws2tcpip.h>
  160. # endif
  161. # else
  162. # ifdef HAVE_WINSOCK_H
  163. # include <winsock.h>
  164. # endif
  165. # endif
  166. #endif
  167. /*
  168. * Define USE_WINSOCK to 2 if we have and use WINSOCK2 API, else
  169. * define USE_WINSOCK to 1 if we have and use WINSOCK API, else
  170. * undefine USE_WINSOCK.
  171. */
  172. #undef USE_WINSOCK
  173. #ifdef HAVE_WINSOCK2_H
  174. # define USE_WINSOCK 2
  175. #else
  176. # ifdef HAVE_WINSOCK_H
  177. # define USE_WINSOCK 1
  178. # endif
  179. #endif
  180. #ifdef HAVE_EXTRA_STRICMP_H
  181. # include <extra/stricmp.h>
  182. #endif
  183. #ifdef HAVE_EXTRA_STRDUP_H
  184. # include <extra/strdup.h>
  185. #endif
  186. #ifdef TPF
  187. # include <strings.h> /* for bzero, strcasecmp, and strncasecmp */
  188. # include <string.h> /* for strcpy and strlen */
  189. # include <stdlib.h> /* for rand and srand */
  190. # include <sys/socket.h> /* for select and ioctl*/
  191. # include <netdb.h> /* for in_addr_t definition */
  192. # include <tpf/sysapi.h> /* for tpf_process_signals */
  193. #endif
  194. #include <stdio.h>
  195. #ifdef HAVE_ASSERT_H
  196. #include <assert.h>
  197. #endif
  198. #include <errno.h>
  199. #ifdef __TANDEM /* for nsr-tandem-nsk systems */
  200. #include <floss.h>
  201. #endif
  202. #ifndef STDC_HEADERS /* no standard C headers! */
  203. #include <curl/stdcheaders.h>
  204. #endif
  205. /*
  206. * PellesC kludge section (yikes);
  207. * - It has 'ssize_t', but it is in <unistd.h>. The way the headers
  208. * on Win32 are included, forces me to include this header here.
  209. * - sys_nerr, EINTR is missing in v4.0 or older.
  210. */
  211. #ifdef __POCC__
  212. #include <sys/types.h>
  213. #include <unistd.h>
  214. #if (__POCC__ <= 400)
  215. #define sys_nerr EILSEQ /* for strerror.c */
  216. #define EINTR -1 /* for select.c */
  217. #endif
  218. #endif
  219. /*
  220. * Salford-C kludge section (mostly borrowed from wxWidgets).
  221. */
  222. #ifdef __SALFORDC__
  223. #pragma suppress 353 /* Possible nested comments */
  224. #pragma suppress 593 /* Define not used */
  225. #pragma suppress 61 /* enum has no name */
  226. #pragma suppress 106 /* unnamed, unused parameter */
  227. #include <clib.h>
  228. #endif
  229. /*
  230. * Large file (>2Gb) support using WIN32 functions.
  231. */
  232. #ifdef USE_WIN32_LARGE_FILES
  233. # include <io.h>
  234. # include <sys/types.h>
  235. # include <sys/stat.h>
  236. # define lseek(fdes,offset,whence) _lseeki64(fdes, offset, whence)
  237. # define fstat(fdes,stp) _fstati64(fdes, stp)
  238. # define stat(fname,stp) _stati64(fname, stp)
  239. # define struct_stat struct _stati64
  240. #endif
  241. /*
  242. * Small file (<2Gb) support using WIN32 functions.
  243. */
  244. #ifdef USE_WIN32_SMALL_FILES
  245. # include <io.h>
  246. # include <sys/types.h>
  247. # include <sys/stat.h>
  248. # define lseek(fdes,offset,whence) _lseek(fdes, (long)offset, whence)
  249. # define fstat(fdes,stp) _fstat(fdes, stp)
  250. # define stat(fname,stp) _stat(fname, stp)
  251. # define struct_stat struct _stat
  252. #endif
  253. #ifndef struct_stat
  254. # define struct_stat struct stat
  255. #endif
  256. /*
  257. * Default sizeof(off_t) in case it hasn't been defined in config file.
  258. */
  259. #ifndef SIZEOF_OFF_T
  260. # if defined(__VMS) && (defined(__alpha) || defined(__ia64))
  261. # if defined(_LARGEFILE)
  262. # define SIZEOF_OFF_T 8
  263. # endif
  264. # elif defined(__OS400__) && defined(__ILEC400__)
  265. # if defined(_LARGE_FILES)
  266. # define SIZEOF_OFF_T 8
  267. # endif
  268. # elif defined(__MVS__) && defined(__IBMC__)
  269. # if defined(_LP64) || defined(_LARGE_FILES)
  270. # define SIZEOF_OFF_T 8
  271. # endif
  272. # elif defined(__370__) && defined(__IBMC__)
  273. # if defined(_LP64) || defined(_LARGE_FILES)
  274. # define SIZEOF_OFF_T 8
  275. # endif
  276. # endif
  277. # ifndef SIZEOF_OFF_T
  278. # define SIZEOF_OFF_T 4
  279. # endif
  280. #endif
  281. /* Below we define some functions. They should
  282. 1. close a socket
  283. 4. set the SIGALRM signal timeout
  284. 5. set dir/file naming defines
  285. */
  286. #ifdef WIN32
  287. #if !defined(__CYGWIN__)
  288. #define sclose(x) closesocket(x)
  289. #undef HAVE_ALARM
  290. #else
  291. /* gcc-for-win is still good :) */
  292. #define sclose(x) close(x)
  293. #define HAVE_ALARM
  294. #endif /* !GNU or mingw */
  295. #define DIR_CHAR "\\"
  296. #define DOT_CHAR "_"
  297. #else /* WIN32 */
  298. #ifdef MSDOS /* Watt-32 */
  299. #include <sys/ioctl.h>
  300. #define sclose(x) close_s(x)
  301. #define select(n,r,w,x,t) select_s(n,r,w,x,t)
  302. #define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z))
  303. #define IOCTL_3_ARGS
  304. #include <tcp.h>
  305. #ifdef word
  306. #undef word
  307. #endif
  308. #ifdef byte
  309. #undef byte
  310. #endif
  311. #else /* MSDOS */
  312. #ifdef __BEOS__
  313. #define sclose(x) closesocket(x)
  314. #else /* __BEOS__ */
  315. #define sclose(x) close(x)
  316. #endif /* __BEOS__ */
  317. #define HAVE_ALARM
  318. #endif /* MSDOS */
  319. #ifdef _AMIGASF
  320. #undef HAVE_ALARM
  321. #undef sclose
  322. #define sclose(x) CloseSocket(x)
  323. #endif
  324. #ifdef __minix
  325. /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
  326. extern char * strtok_r(char *s, const char *delim, char **last);
  327. extern struct tm * gmtime_r(const time_t * const timep, struct tm *tmp);
  328. #endif
  329. #ifdef __SYMBIAN32__
  330. #undef HAVE_ALARM
  331. #endif
  332. #define DIR_CHAR "/"
  333. #ifndef DOT_CHAR
  334. #define DOT_CHAR "."
  335. #endif
  336. #ifdef MSDOS
  337. #undef DOT_CHAR
  338. #define DOT_CHAR "_"
  339. #endif
  340. #ifndef fileno /* sunos 4 have this as a macro! */
  341. int fileno( FILE *stream);
  342. #endif
  343. #endif /* WIN32 */
  344. #if defined(WIN32) && !defined(__CYGWIN__) && !defined(USE_ARES) && \
  345. !defined(__LCC__) /* lcc-win32 doesn't have _beginthreadex() */
  346. #ifdef ENABLE_IPV6
  347. #define USE_THREADING_GETADDRINFO
  348. #else
  349. #define USE_THREADING_GETHOSTBYNAME /* Cygwin uses alarm() function */
  350. #endif
  351. #endif
  352. /* "cl -ML" or "cl -MLd" implies a single-threaded runtime library where
  353. _beginthreadex() is not available */
  354. #if (defined(_MSC_VER) && !defined(__POCC__)) && !defined(_MT) && !defined(USE_ARES)
  355. #undef USE_THREADING_GETADDRINFO
  356. #undef USE_THREADING_GETHOSTBYNAME
  357. #define CURL_NO__BEGINTHREADEX
  358. #endif
  359. /*
  360. * msvc 6.0 does not have struct sockaddr_storage and
  361. * does not define IPPROTO_ESP in winsock2.h. But both
  362. * are available if PSDK is properly installed.
  363. */
  364. #ifdef _MSC_VER
  365. #if !defined(HAVE_WINSOCK2_H) || ((_MSC_VER < 1300) && !defined(IPPROTO_ESP))
  366. #undef HAVE_STRUCT_SOCKADDR_STORAGE
  367. #endif
  368. #endif
  369. #ifdef mpeix
  370. #define IOCTL_3_ARGS
  371. #endif
  372. #ifdef NETWARE
  373. int netware_init(void);
  374. #ifndef __NOVELL_LIBC__
  375. #include <sys/bsdskt.h>
  376. #include <sys/timeval.h>
  377. #endif
  378. #undef HAVE_ALARM
  379. #endif
  380. #if defined(HAVE_LIBIDN) && defined(HAVE_TLD_H)
  381. /* The lib was present and the tld.h header (which is missing in libidn 0.3.X
  382. but we only work with libidn 0.4.1 or later) */
  383. #define USE_LIBIDN
  384. #endif
  385. #ifndef SIZEOF_TIME_T
  386. /* assume default size of time_t to be 32 bit */
  387. #define SIZEOF_TIME_T 4
  388. #endif
  389. #define LIBIDN_REQUIRED_VERSION "0.4.1"
  390. #ifdef __UCLIBC__
  391. #define HAVE_INET_NTOA_R_2_ARGS 1
  392. #endif
  393. #if defined(USE_GNUTLS) || defined(USE_SSLEAY) || defined(USE_NSS) || defined(USE_QSOSSL)
  394. #define USE_SSL /* SSL support has been enabled */
  395. #endif
  396. #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_NTLM)
  397. #if defined(USE_SSLEAY) || defined(USE_WINDOWS_SSPI)
  398. #define USE_NTLM
  399. #endif
  400. #endif
  401. /* non-configure builds may define CURL_WANTS_CA_BUNDLE_ENV */
  402. #if defined(CURL_WANTS_CA_BUNDLE_ENV) && !defined(CURL_CA_BUNDLE)
  403. #define CURL_CA_BUNDLE getenv("CURL_CA_BUNDLE")
  404. #endif
  405. /*
  406. * Include macros and defines that should only be processed once.
  407. */
  408. #ifndef __SETUP_ONCE_H
  409. #include "setup_once.h"
  410. #endif
  411. #endif /* __LIB_CURL_SETUP_H */