setup.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. #ifndef HEADER_CURL_LIB_SETUP_H
  2. #define HEADER_CURL_LIB_SETUP_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, 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. ***************************************************************************/
  24. /*
  25. * Define WIN32 when build target is Win32 API
  26. */
  27. #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) && !defined(__SYMBIAN32__)
  28. #define WIN32
  29. #endif
  30. /*
  31. * Include configuration script results or hand-crafted
  32. * configuration file for platforms which lack config tool.
  33. */
  34. #ifdef HAVE_CONFIG_H
  35. #include "curl_config.h"
  36. #else /* HAVE_CONFIG_H */
  37. #ifdef _WIN32_WCE
  38. # include "config-win32ce.h"
  39. #else
  40. # ifdef WIN32
  41. # include "config-win32.h"
  42. # endif
  43. #endif
  44. #if defined(macintosh) && defined(__MRC__)
  45. # include "config-mac.h"
  46. #endif
  47. #ifdef __AMIGA__
  48. # include "amigaos.h"
  49. #endif
  50. #ifdef __SYMBIAN32__
  51. # include "config-symbian.h"
  52. #endif
  53. #ifdef __OS400__
  54. # include "config-os400.h"
  55. #endif
  56. #ifdef TPF
  57. # include "config-tpf.h"
  58. #endif
  59. #ifdef __VXWORKS__
  60. # include "config-vxworks.h"
  61. #endif
  62. #endif /* HAVE_CONFIG_H */
  63. /* ================================================================ */
  64. /* Definition of preprocessor macros/symbols which modify compiler */
  65. /* behavior 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. * AIX 4.3 and newer needs _THREAD_SAFE defined to build
  73. * proper reentrant code. Others may also need it.
  74. */
  75. #ifdef NEED_THREAD_SAFE
  76. # ifndef _THREAD_SAFE
  77. # define _THREAD_SAFE
  78. # endif
  79. #endif
  80. /*
  81. * Tru64 needs _REENTRANT set for a few function prototypes and
  82. * things to appear in the system header files. Unixware needs it
  83. * to build proper reentrant code. Others may also need it.
  84. */
  85. #ifdef NEED_REENTRANT
  86. # ifndef _REENTRANT
  87. # define _REENTRANT
  88. # endif
  89. #endif
  90. /* ================================================================ */
  91. /* If you need to include a system header file for your platform, */
  92. /* please, do it beyond the point further indicated in this file. */
  93. /* ================================================================ */
  94. /*
  95. * libcurl's external interface definitions are also used internally,
  96. * and might also include required system header files to define them.
  97. */
  98. #include <curl/curlbuild.h>
  99. /*
  100. * Compile time sanity checks must also be done when building the library.
  101. */
  102. #include <curl/curlrules.h>
  103. /*
  104. * Ensure that no one is using the old SIZEOF_CURL_OFF_T macro
  105. */
  106. #ifdef SIZEOF_CURL_OFF_T
  107. # error "SIZEOF_CURL_OFF_T shall not be defined!"
  108. Error Compilation_aborted_SIZEOF_CURL_OFF_T_shall_not_be_defined
  109. #endif
  110. /*
  111. * Set up internal curl_off_t formatting string directives for
  112. * exclusive use with libcurl's internal *printf functions.
  113. */
  114. #ifdef FORMAT_OFF_T
  115. # error "FORMAT_OFF_T shall not be defined before this point!"
  116. Error Compilation_aborted_FORMAT_OFF_T_already_defined
  117. #endif
  118. #ifdef FORMAT_OFF_TU
  119. # error "FORMAT_OFF_TU shall not be defined before this point!"
  120. Error Compilation_aborted_FORMAT_OFF_TU_already_defined
  121. #endif
  122. #if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
  123. # define FORMAT_OFF_T "lld"
  124. # define FORMAT_OFF_TU "llu"
  125. #else
  126. # define FORMAT_OFF_T "ld"
  127. # define FORMAT_OFF_TU "lu"
  128. #endif
  129. /*
  130. * Disable other protocols when http is the only one desired.
  131. */
  132. #ifdef HTTP_ONLY
  133. # define CURL_DISABLE_TFTP
  134. # define CURL_DISABLE_FTP
  135. # define CURL_DISABLE_LDAP
  136. # define CURL_DISABLE_TELNET
  137. # define CURL_DISABLE_DICT
  138. # define CURL_DISABLE_FILE
  139. # define CURL_DISABLE_RTSP
  140. #endif
  141. /*
  142. * When http is disabled rtsp is not supported.
  143. */
  144. #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP)
  145. # define CURL_DISABLE_RTSP
  146. #endif
  147. /* ================================================================ */
  148. /* No system header file shall be included in this file before this */
  149. /* point. The only allowed ones are those included from curlbuild.h */
  150. /* ================================================================ */
  151. /*
  152. * OS/400 setup file includes some system headers.
  153. */
  154. #ifdef __OS400__
  155. # include "setup-os400.h"
  156. #endif
  157. /*
  158. * Include header files for windows builds before redefining anything.
  159. * Use this preprocessor block only to include or exclude windows.h,
  160. * winsock2.h, ws2tcpip.h or winsock.h. Any other windows thing belongs
  161. * to any other further and independent block. Under Cygwin things work
  162. * just as under linux (e.g. <sys/socket.h>) and the winsock headers should
  163. * never be included when __CYGWIN__ is defined. configure script takes
  164. * care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK_H, HAVE_WINSOCK2_H,
  165. * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined.
  166. */
  167. #ifdef HAVE_WINDOWS_H
  168. # ifndef WIN32_LEAN_AND_MEAN
  169. # define WIN32_LEAN_AND_MEAN
  170. # endif
  171. # include <windows.h>
  172. # ifdef HAVE_WINSOCK2_H
  173. # include <winsock2.h>
  174. # ifdef HAVE_WS2TCPIP_H
  175. # include <ws2tcpip.h>
  176. # endif
  177. # else
  178. # ifdef HAVE_WINSOCK_H
  179. # include <winsock.h>
  180. # endif
  181. # endif
  182. #endif
  183. /*
  184. * Define USE_WINSOCK to 2 if we have and use WINSOCK2 API, else
  185. * define USE_WINSOCK to 1 if we have and use WINSOCK API, else
  186. * undefine USE_WINSOCK.
  187. */
  188. #undef USE_WINSOCK
  189. #ifdef HAVE_WINSOCK2_H
  190. # define USE_WINSOCK 2
  191. #else
  192. # ifdef HAVE_WINSOCK_H
  193. # define USE_WINSOCK 1
  194. # endif
  195. #endif
  196. #ifdef HAVE_EXTRA_STRICMP_H
  197. # include <extra/stricmp.h>
  198. #endif
  199. #ifdef HAVE_EXTRA_STRDUP_H
  200. # include <extra/strdup.h>
  201. #endif
  202. #ifdef TPF
  203. # include <strings.h> /* for bzero, strcasecmp, and strncasecmp */
  204. # include <string.h> /* for strcpy and strlen */
  205. # include <stdlib.h> /* for rand and srand */
  206. # include <sys/socket.h> /* for select and ioctl*/
  207. # include <netdb.h> /* for in_addr_t definition */
  208. # include <tpf/sysapi.h> /* for tpf_process_signals */
  209. /* change which select is used for libcurl */
  210. # define select(a,b,c,d,e) tpf_select_libcurl(a,b,c,d,e)
  211. #endif
  212. #ifdef __VXWORKS__
  213. # include <sockLib.h> /* for generic BSD socket functions */
  214. # include <ioLib.h> /* for basic I/O interface functions */
  215. #endif
  216. #include <stdio.h>
  217. #ifdef HAVE_ASSERT_H
  218. #include <assert.h>
  219. #endif
  220. #include <errno.h>
  221. #ifdef __TANDEM /* for nsr-tandem-nsk systems */
  222. #include <floss.h>
  223. #endif
  224. #ifndef STDC_HEADERS /* no standard C headers! */
  225. #include <curl/stdcheaders.h>
  226. #endif
  227. #ifdef __POCC__
  228. # include <sys/types.h>
  229. # include <unistd.h>
  230. # define sys_nerr EILSEQ
  231. #endif
  232. /*
  233. * Salford-C kludge section (mostly borrowed from wxWidgets).
  234. */
  235. #ifdef __SALFORDC__
  236. #pragma suppress 353 /* Possible nested comments */
  237. #pragma suppress 593 /* Define not used */
  238. #pragma suppress 61 /* enum has no name */
  239. #pragma suppress 106 /* unnamed, unused parameter */
  240. #include <clib.h>
  241. #endif
  242. /*
  243. * Large file (>2Gb) support using WIN32 functions.
  244. */
  245. #ifdef USE_WIN32_LARGE_FILES
  246. # include <io.h>
  247. # include <sys/types.h>
  248. # include <sys/stat.h>
  249. # define lseek(fdes,offset,whence) _lseeki64(fdes, offset, whence)
  250. # define fstat(fdes,stp) _fstati64(fdes, stp)
  251. # define stat(fname,stp) _stati64(fname, stp)
  252. # define struct_stat struct _stati64
  253. # define LSEEK_ERROR (__int64)-1
  254. #endif
  255. /*
  256. * Small file (<2Gb) support using WIN32 functions.
  257. */
  258. #ifdef USE_WIN32_SMALL_FILES
  259. # include <io.h>
  260. # include <sys/types.h>
  261. # include <sys/stat.h>
  262. # define lseek(fdes,offset,whence) _lseek(fdes, (long)offset, whence)
  263. # define fstat(fdes,stp) _fstat(fdes, stp)
  264. # define stat(fname,stp) _stat(fname, stp)
  265. # define struct_stat struct _stat
  266. # define LSEEK_ERROR (long)-1
  267. #endif
  268. #ifndef struct_stat
  269. # define struct_stat struct stat
  270. #endif
  271. #ifndef LSEEK_ERROR
  272. # define LSEEK_ERROR (off_t)-1
  273. #endif
  274. /*
  275. * Default sizeof(off_t) in case it hasn't been defined in config file.
  276. */
  277. #ifndef SIZEOF_OFF_T
  278. # if defined(__VMS) && !defined(__VAX)
  279. # if defined(_LARGEFILE)
  280. # define SIZEOF_OFF_T 8
  281. # endif
  282. # elif defined(__OS400__) && defined(__ILEC400__)
  283. # if defined(_LARGE_FILES)
  284. # define SIZEOF_OFF_T 8
  285. # endif
  286. # elif defined(__MVS__) && defined(__IBMC__)
  287. # if defined(_LP64) || defined(_LARGE_FILES)
  288. # define SIZEOF_OFF_T 8
  289. # endif
  290. # elif defined(__370__) && defined(__IBMC__)
  291. # if defined(_LP64) || defined(_LARGE_FILES)
  292. # define SIZEOF_OFF_T 8
  293. # endif
  294. # endif
  295. # ifndef SIZEOF_OFF_T
  296. # define SIZEOF_OFF_T 4
  297. # endif
  298. #endif
  299. /*
  300. * Arg 2 type for gethostname in case it hasn't been defined in config file.
  301. */
  302. #ifndef GETHOSTNAME_TYPE_ARG2
  303. # ifdef USE_WINSOCK
  304. # define GETHOSTNAME_TYPE_ARG2 int
  305. # else
  306. # define GETHOSTNAME_TYPE_ARG2 size_t
  307. # endif
  308. #endif
  309. /* Below we define some functions. They should
  310. 4. set the SIGALRM signal timeout
  311. 5. set dir/file naming defines
  312. */
  313. #ifdef WIN32
  314. # define DIR_CHAR "\\"
  315. # define DOT_CHAR "_"
  316. #else /* WIN32 */
  317. # ifdef MSDOS /* Watt-32 */
  318. # include <sys/ioctl.h>
  319. # define select(n,r,w,x,t) select_s(n,r,w,x,t)
  320. # define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z))
  321. # include <tcp.h>
  322. # ifdef word
  323. # undef word
  324. # endif
  325. # ifdef byte
  326. # undef byte
  327. # endif
  328. # endif /* MSDOS */
  329. # ifdef __minix
  330. /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
  331. extern char * strtok_r(char *s, const char *delim, char **last);
  332. extern struct tm * gmtime_r(const time_t * const timep, struct tm *tmp);
  333. # endif
  334. # define DIR_CHAR "/"
  335. # ifndef DOT_CHAR
  336. # define DOT_CHAR "."
  337. # endif
  338. # ifdef MSDOS
  339. # undef DOT_CHAR
  340. # define DOT_CHAR "_"
  341. # endif
  342. # ifndef fileno /* sunos 4 have this as a macro! */
  343. int fileno( FILE *stream);
  344. # endif
  345. #endif /* WIN32 */
  346. /*
  347. * msvc 6.0 requires PSDK in order to have INET6_ADDRSTRLEN
  348. * defined in ws2tcpip.h as well as to provide IPv6 support.
  349. */
  350. #if defined(_MSC_VER) && !defined(__POCC__)
  351. # if !defined(HAVE_WS2TCPIP_H) || \
  352. ((_MSC_VER < 1300) && !defined(INET6_ADDRSTRLEN))
  353. # undef HAVE_GETADDRINFO_THREADSAFE
  354. # undef HAVE_FREEADDRINFO
  355. # undef HAVE_GETADDRINFO
  356. # undef HAVE_GETNAMEINFO
  357. # undef ENABLE_IPV6
  358. # endif
  359. #endif
  360. /* ---------------------------------------------------------------- */
  361. /* resolver specialty compile-time defines */
  362. /* CURLRES_* defines to use in the host*.c sources */
  363. /* ---------------------------------------------------------------- */
  364. /*
  365. * lcc-win32 doesn't have _beginthreadex(), lacks threads support.
  366. */
  367. #if defined(__LCC__) && defined(WIN32)
  368. # undef USE_THREADS_POSIX
  369. # undef USE_THREADS_WIN32
  370. #endif
  371. /*
  372. * MSVC threads support requires a multi-threaded runtime library.
  373. * _beginthreadex() is not available in single-threaded ones.
  374. */
  375. #if defined(_MSC_VER) && !defined(__POCC__) && !defined(_MT)
  376. # undef USE_THREADS_POSIX
  377. # undef USE_THREADS_WIN32
  378. #endif
  379. /*
  380. * Mutually exclusive CURLRES_* definitions.
  381. */
  382. #ifdef USE_ARES
  383. # define CURLRES_ASYNCH
  384. # define CURLRES_ARES
  385. #elif defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
  386. # define CURLRES_ASYNCH
  387. # define CURLRES_THREADED
  388. #else
  389. # define CURLRES_SYNCH
  390. #endif
  391. #ifdef ENABLE_IPV6
  392. # define CURLRES_IPV6
  393. #else
  394. # define CURLRES_IPV4
  395. #endif
  396. /* ---------------------------------------------------------------- */
  397. /*
  398. * When using WINSOCK, TELNET protocol requires WINSOCK2 API.
  399. */
  400. #if defined(USE_WINSOCK) && (USE_WINSOCK != 2)
  401. # define CURL_DISABLE_TELNET 1
  402. #endif
  403. /*
  404. * msvc 6.0 does not have struct sockaddr_storage and
  405. * does not define IPPROTO_ESP in winsock2.h. But both
  406. * are available if PSDK is properly installed.
  407. */
  408. #if defined(_MSC_VER) && !defined(__POCC__)
  409. # if !defined(HAVE_WINSOCK2_H) || ((_MSC_VER < 1300) && !defined(IPPROTO_ESP))
  410. # undef HAVE_STRUCT_SOCKADDR_STORAGE
  411. # endif
  412. #endif
  413. /*
  414. * Intentionally fail to build when using msvc 6.0 without PSDK installed.
  415. * The brave of heart can circumvent this, defining ALLOW_MSVC6_WITHOUT_PSDK
  416. * in lib/config-win32.h although absolutely discouraged and unsupported.
  417. */
  418. #if defined(_MSC_VER) && !defined(__POCC__)
  419. # if !defined(HAVE_WINDOWS_H) || ((_MSC_VER < 1300) && !defined(_FILETIME_))
  420. # if !defined(ALLOW_MSVC6_WITHOUT_PSDK)
  421. # error MSVC 6.0 requires "February 2003 Platform SDK" a.k.a. "Windows Server 2003 PSDK"
  422. # else
  423. # define CURL_DISABLE_LDAP 1
  424. # endif
  425. # endif
  426. #endif
  427. #ifdef NETWARE
  428. int netware_init(void);
  429. #ifndef __NOVELL_LIBC__
  430. #include <sys/bsdskt.h>
  431. #include <sys/timeval.h>
  432. #endif
  433. #endif
  434. #if defined(HAVE_LIBIDN) && defined(HAVE_TLD_H)
  435. /* The lib was present and the tld.h header (which is missing in libidn 0.3.X
  436. but we only work with libidn 0.4.1 or later) */
  437. #define USE_LIBIDN
  438. #endif
  439. #ifndef SIZEOF_TIME_T
  440. /* assume default size of time_t to be 32 bit */
  441. #define SIZEOF_TIME_T 4
  442. #endif
  443. #define LIBIDN_REQUIRED_VERSION "0.4.1"
  444. #if defined(USE_GNUTLS) || defined(USE_SSLEAY) || defined(USE_NSS) || defined(USE_QSOSSL) || defined(USE_POLARSSL) || defined(USE_AXTLS)
  445. #define USE_SSL /* SSL support has been enabled */
  446. #endif
  447. #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_NTLM)
  448. #if defined(USE_SSLEAY) || defined(USE_WINDOWS_SSPI) || defined(USE_GNUTLS) || defined(USE_NSS)
  449. #define USE_NTLM
  450. #endif
  451. #endif
  452. /* non-configure builds may define CURL_WANTS_CA_BUNDLE_ENV */
  453. #if defined(CURL_WANTS_CA_BUNDLE_ENV) && !defined(CURL_CA_BUNDLE)
  454. #define CURL_CA_BUNDLE getenv("CURL_CA_BUNDLE")
  455. #endif
  456. /* Define S_ISREG if not defined by system headers, f.e. MSVC */
  457. #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
  458. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  459. #endif
  460. /*
  461. * Include macros and defines that should only be processed once.
  462. */
  463. #ifndef __SETUP_ONCE_H
  464. #include "setup_once.h"
  465. #endif
  466. #endif /* HEADER_CURL_LIB_SETUP_H */