curl_setup.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. #ifndef HEADER_CURL_SETUP_H
  2. #define HEADER_CURL_SETUP_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 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 https://curl.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. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. #if defined(BUILDING_LIBCURL) && !defined(CURL_NO_OLDIES)
  27. #define CURL_NO_OLDIES
  28. #endif
  29. /* FIXME: Delete this once the warnings have been fixed. */
  30. #if !defined(CURL_WARN_SIGN_CONVERSION)
  31. #ifdef __GNUC__
  32. #pragma GCC diagnostic ignored "-Wsign-conversion"
  33. #endif
  34. #endif
  35. /* Set default _WIN32_WINNT */
  36. #ifdef __MINGW32__
  37. #include <_mingw.h>
  38. #endif
  39. /*
  40. * Disable Visual Studio warnings:
  41. * 4127 "conditional expression is constant"
  42. */
  43. #ifdef _MSC_VER
  44. #pragma warning(disable:4127)
  45. #endif
  46. #ifdef _WIN32
  47. /*
  48. * Don't include unneeded stuff in Windows headers to avoid compiler
  49. * warnings and macro clashes.
  50. * Make sure to define this macro before including any Windows headers.
  51. */
  52. # ifndef WIN32_LEAN_AND_MEAN
  53. # define WIN32_LEAN_AND_MEAN
  54. # endif
  55. # ifndef NOGDI
  56. # define NOGDI
  57. # endif
  58. /* Detect Windows App environment which has a restricted access
  59. * to the Win32 APIs. */
  60. # if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \
  61. defined(WINAPI_FAMILY)
  62. # include <winapifamily.h>
  63. # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
  64. !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
  65. # define CURL_WINDOWS_APP
  66. # endif
  67. # endif
  68. #endif
  69. /*
  70. * Include configuration script results or hand-crafted
  71. * configuration file for platforms which lack config tool.
  72. */
  73. #ifdef HAVE_CONFIG_H
  74. #include "curl_config.h"
  75. #else /* HAVE_CONFIG_H */
  76. #ifdef _WIN32_WCE
  77. # include "config-win32ce.h"
  78. #else
  79. # ifdef _WIN32
  80. # include "config-win32.h"
  81. # endif
  82. #endif
  83. #ifdef macintosh
  84. # include "config-mac.h"
  85. #endif
  86. #ifdef __riscos__
  87. # include "config-riscos.h"
  88. #endif
  89. #ifdef __AMIGA__
  90. # include "config-amigaos.h"
  91. #endif
  92. #ifdef __OS400__
  93. # include "config-os400.h"
  94. #endif
  95. #ifdef __PLAN9__
  96. # include "config-plan9.h"
  97. #endif
  98. #ifdef MSDOS
  99. # include "config-dos.h"
  100. #endif
  101. #endif /* HAVE_CONFIG_H */
  102. /* ================================================================ */
  103. /* Definition of preprocessor macros/symbols which modify compiler */
  104. /* behavior or generated code characteristics must be done here, */
  105. /* as appropriate, before any system header file is included. It is */
  106. /* also possible to have them defined in the config file included */
  107. /* before this point. As a result of all this we frown inclusion of */
  108. /* system header files in our config files, avoid this at any cost. */
  109. /* ================================================================ */
  110. /*
  111. * AIX 4.3 and newer needs _THREAD_SAFE defined to build
  112. * proper reentrant code. Others may also need it.
  113. */
  114. #ifdef NEED_THREAD_SAFE
  115. # ifndef _THREAD_SAFE
  116. # define _THREAD_SAFE
  117. # endif
  118. #endif
  119. /*
  120. * Tru64 needs _REENTRANT set for a few function prototypes and
  121. * things to appear in the system header files. Unixware needs it
  122. * to build proper reentrant code. Others may also need it.
  123. */
  124. #ifdef NEED_REENTRANT
  125. # ifndef _REENTRANT
  126. # define _REENTRANT
  127. # endif
  128. #endif
  129. /* Solaris needs this to get a POSIX-conformant getpwuid_r */
  130. #if defined(sun) || defined(__sun)
  131. # ifndef _POSIX_PTHREAD_SEMANTICS
  132. # define _POSIX_PTHREAD_SEMANTICS 1
  133. # endif
  134. #endif
  135. /* ================================================================ */
  136. /* If you need to include a system header file for your platform, */
  137. /* please, do it beyond the point further indicated in this file. */
  138. /* ================================================================ */
  139. /*
  140. * Disable other protocols when http is the only one desired.
  141. */
  142. #ifdef HTTP_ONLY
  143. # ifndef CURL_DISABLE_DICT
  144. # define CURL_DISABLE_DICT
  145. # endif
  146. # ifndef CURL_DISABLE_FILE
  147. # define CURL_DISABLE_FILE
  148. # endif
  149. # ifndef CURL_DISABLE_FTP
  150. # define CURL_DISABLE_FTP
  151. # endif
  152. # ifndef CURL_DISABLE_GOPHER
  153. # define CURL_DISABLE_GOPHER
  154. # endif
  155. # ifndef CURL_DISABLE_IMAP
  156. # define CURL_DISABLE_IMAP
  157. # endif
  158. # ifndef CURL_DISABLE_LDAP
  159. # define CURL_DISABLE_LDAP
  160. # endif
  161. # ifndef CURL_DISABLE_LDAPS
  162. # define CURL_DISABLE_LDAPS
  163. # endif
  164. # ifndef CURL_DISABLE_MQTT
  165. # define CURL_DISABLE_MQTT
  166. # endif
  167. # ifndef CURL_DISABLE_POP3
  168. # define CURL_DISABLE_POP3
  169. # endif
  170. # ifndef CURL_DISABLE_RTSP
  171. # define CURL_DISABLE_RTSP
  172. # endif
  173. # ifndef CURL_DISABLE_SMB
  174. # define CURL_DISABLE_SMB
  175. # endif
  176. # ifndef CURL_DISABLE_SMTP
  177. # define CURL_DISABLE_SMTP
  178. # endif
  179. # ifndef CURL_DISABLE_TELNET
  180. # define CURL_DISABLE_TELNET
  181. # endif
  182. # ifndef CURL_DISABLE_TFTP
  183. # define CURL_DISABLE_TFTP
  184. # endif
  185. #endif
  186. /*
  187. * When http is disabled rtsp is not supported.
  188. */
  189. #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP)
  190. # define CURL_DISABLE_RTSP
  191. #endif
  192. /*
  193. * When HTTP is disabled, disable HTTP-only features
  194. */
  195. #if defined(CURL_DISABLE_HTTP)
  196. # define CURL_DISABLE_ALTSVC 1
  197. # define CURL_DISABLE_COOKIES 1
  198. # define CURL_DISABLE_BASIC_AUTH 1
  199. # define CURL_DISABLE_BEARER_AUTH 1
  200. # define CURL_DISABLE_AWS 1
  201. # define CURL_DISABLE_DOH 1
  202. # define CURL_DISABLE_FORM_API 1
  203. # define CURL_DISABLE_HEADERS_API 1
  204. # define CURL_DISABLE_HSTS 1
  205. # define CURL_DISABLE_HTTP_AUTH 1
  206. #endif
  207. /* ================================================================ */
  208. /* No system header file shall be included in this file before this */
  209. /* point. */
  210. /* ================================================================ */
  211. /*
  212. * OS/400 setup file includes some system headers.
  213. */
  214. #ifdef __OS400__
  215. # include "setup-os400.h"
  216. #endif
  217. /*
  218. * VMS setup file includes some system headers.
  219. */
  220. #ifdef __VMS
  221. # include "setup-vms.h"
  222. #endif
  223. /*
  224. * Windows setup file includes some system headers.
  225. */
  226. #ifdef _WIN32
  227. # include "setup-win32.h"
  228. #endif
  229. #include <curl/system.h>
  230. /* curl uses its own printf() function internally. It understands the GNU
  231. * format. Use this format, so that is matches the GNU format attribute we
  232. * use with the mingw compiler, allowing it to verify them at compile-time.
  233. */
  234. #ifdef __MINGW32__
  235. # undef CURL_FORMAT_CURL_OFF_T
  236. # undef CURL_FORMAT_CURL_OFF_TU
  237. # define CURL_FORMAT_CURL_OFF_T "lld"
  238. # define CURL_FORMAT_CURL_OFF_TU "llu"
  239. #endif
  240. /* based on logic in "curl/mprintf.h" */
  241. #if (defined(__GNUC__) || defined(__clang__)) && \
  242. defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
  243. !defined(CURL_NO_FMT_CHECKS)
  244. #if defined(__MINGW32__) && !defined(__clang__)
  245. #define CURL_PRINTF(fmt, arg) \
  246. __attribute__((format(gnu_printf, fmt, arg)))
  247. #else
  248. #define CURL_PRINTF(fmt, arg) \
  249. __attribute__((format(__printf__, fmt, arg)))
  250. #endif
  251. #else
  252. #define CURL_PRINTF(fmt, arg)
  253. #endif
  254. /*
  255. * Use getaddrinfo to resolve the IPv4 address literal. If the current network
  256. * interface doesn't support IPv4, but supports IPv6, NAT64, and DNS64,
  257. * performing this task will result in a synthesized IPv6 address.
  258. */
  259. #if defined(__APPLE__) && !defined(USE_ARES)
  260. #include <TargetConditionals.h>
  261. #define USE_RESOLVE_ON_IPS 1
  262. # if TARGET_OS_MAC && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && \
  263. defined(ENABLE_IPV6)
  264. # define CURL_MACOS_CALL_COPYPROXIES 1
  265. # endif
  266. #endif
  267. #ifdef USE_LWIPSOCK
  268. # include <lwip/init.h>
  269. # include <lwip/sockets.h>
  270. # include <lwip/netdb.h>
  271. #endif
  272. #ifdef HAVE_EXTRA_STRICMP_H
  273. # include <extra/stricmp.h>
  274. #endif
  275. #ifdef HAVE_EXTRA_STRDUP_H
  276. # include <extra/strdup.h>
  277. #endif
  278. #ifdef __AMIGA__
  279. # ifdef __amigaos4__
  280. # define __USE_INLINE__
  281. /* use our own resolver which uses runtime feature detection */
  282. # define CURLRES_AMIGA
  283. /* getaddrinfo() currently crashes bsdsocket.library, so disable */
  284. # undef HAVE_GETADDRINFO
  285. # if !(defined(__NEWLIB__) || \
  286. (defined(__CLIB2__) && defined(__THREAD_SAFE)))
  287. /* disable threaded resolver with clib2 - requires newlib or clib-ts */
  288. # undef USE_THREADS_POSIX
  289. # endif
  290. # endif
  291. # include <exec/types.h>
  292. # include <exec/execbase.h>
  293. # include <proto/exec.h>
  294. # include <proto/dos.h>
  295. # include <unistd.h>
  296. # if defined(HAVE_PROTO_BSDSOCKET_H) && \
  297. (!defined(__amigaos4__) || defined(USE_AMISSL))
  298. /* use bsdsocket.library directly, instead of libc networking functions */
  299. # define _SYS_MBUF_H /* m_len define clashes with curl */
  300. # include <proto/bsdsocket.h>
  301. # ifdef __amigaos4__
  302. int Curl_amiga_select(int nfds, fd_set *readfds, fd_set *writefds,
  303. fd_set *errorfds, struct timeval *timeout);
  304. # define select(a,b,c,d,e) Curl_amiga_select(a,b,c,d,e)
  305. # else
  306. # define select(a,b,c,d,e) WaitSelect(a,b,c,d,e,0)
  307. # endif
  308. /* must not use libc's fcntl() on bsdsocket.library sockfds! */
  309. # undef HAVE_FCNTL
  310. # undef HAVE_FCNTL_O_NONBLOCK
  311. # else
  312. /* use libc networking and hence close() and fnctl() */
  313. # undef HAVE_CLOSESOCKET_CAMEL
  314. # undef HAVE_IOCTLSOCKET_CAMEL
  315. # endif
  316. /*
  317. * In clib2 arpa/inet.h warns that some prototypes may clash
  318. * with bsdsocket.library. This avoids the definition of those.
  319. */
  320. # define __NO_NET_API
  321. #endif
  322. #include <stdio.h>
  323. #include <assert.h>
  324. #ifdef __TANDEM /* for ns*-tandem-nsk systems */
  325. # if ! defined __LP64
  326. # include <floss.h> /* FLOSS is only used for 32-bit builds. */
  327. # endif
  328. #endif
  329. #ifndef STDC_HEADERS /* no standard C headers! */
  330. #include <curl/stdcheaders.h>
  331. #endif
  332. /*
  333. * Large file (>2Gb) support using WIN32 functions.
  334. */
  335. #ifdef USE_WIN32_LARGE_FILES
  336. # include <io.h>
  337. # include <sys/types.h>
  338. # include <sys/stat.h>
  339. # undef lseek
  340. # define lseek(fdes,offset,whence) _lseeki64(fdes, offset, whence)
  341. # undef fstat
  342. # define fstat(fdes,stp) _fstati64(fdes, stp)
  343. # undef stat
  344. # define stat(fname,stp) curlx_win32_stat(fname, stp)
  345. # define struct_stat struct _stati64
  346. # define LSEEK_ERROR (__int64)-1
  347. # define open curlx_win32_open
  348. # define fopen(fname,mode) curlx_win32_fopen(fname, mode)
  349. # define access(fname,mode) curlx_win32_access(fname, mode)
  350. int curlx_win32_open(const char *filename, int oflag, ...);
  351. int curlx_win32_stat(const char *path, struct_stat *buffer);
  352. FILE *curlx_win32_fopen(const char *filename, const char *mode);
  353. int curlx_win32_access(const char *path, int mode);
  354. #endif
  355. /*
  356. * Small file (<2Gb) support using WIN32 functions.
  357. */
  358. #ifdef USE_WIN32_SMALL_FILES
  359. # include <io.h>
  360. # include <sys/types.h>
  361. # include <sys/stat.h>
  362. # ifndef _WIN32_WCE
  363. # undef lseek
  364. # define lseek(fdes,offset,whence) _lseek(fdes, (long)offset, whence)
  365. # define fstat(fdes,stp) _fstat(fdes, stp)
  366. # define stat(fname,stp) curlx_win32_stat(fname, stp)
  367. # define struct_stat struct _stat
  368. # define open curlx_win32_open
  369. # define fopen(fname,mode) curlx_win32_fopen(fname, mode)
  370. # define access(fname,mode) curlx_win32_access(fname, mode)
  371. int curlx_win32_stat(const char *path, struct_stat *buffer);
  372. int curlx_win32_open(const char *filename, int oflag, ...);
  373. FILE *curlx_win32_fopen(const char *filename, const char *mode);
  374. int curlx_win32_access(const char *path, int mode);
  375. # endif
  376. # define LSEEK_ERROR (long)-1
  377. #endif
  378. #ifndef struct_stat
  379. # define struct_stat struct stat
  380. #endif
  381. #ifndef LSEEK_ERROR
  382. # define LSEEK_ERROR (off_t)-1
  383. #endif
  384. #ifndef SIZEOF_TIME_T
  385. /* assume default size of time_t to be 32 bit */
  386. #define SIZEOF_TIME_T 4
  387. #endif
  388. #ifndef SIZEOF_CURL_SOCKET_T
  389. /* configure and cmake check and set the define */
  390. # ifdef _WIN64
  391. # define SIZEOF_CURL_SOCKET_T 8
  392. # else
  393. /* default guess */
  394. # define SIZEOF_CURL_SOCKET_T 4
  395. # endif
  396. #endif
  397. #if SIZEOF_CURL_SOCKET_T < 8
  398. # define CURL_FORMAT_SOCKET_T "d"
  399. #elif defined(__MINGW32__)
  400. # define CURL_FORMAT_SOCKET_T "zd"
  401. #else
  402. # define CURL_FORMAT_SOCKET_T "qd"
  403. #endif
  404. /*
  405. * Default sizeof(off_t) in case it hasn't been defined in config file.
  406. */
  407. #ifndef SIZEOF_OFF_T
  408. # if defined(__VMS) && !defined(__VAX)
  409. # if defined(_LARGEFILE)
  410. # define SIZEOF_OFF_T 8
  411. # endif
  412. # elif defined(__OS400__) && defined(__ILEC400__)
  413. # if defined(_LARGE_FILES)
  414. # define SIZEOF_OFF_T 8
  415. # endif
  416. # elif defined(__MVS__) && defined(__IBMC__)
  417. # if defined(_LP64) || defined(_LARGE_FILES)
  418. # define SIZEOF_OFF_T 8
  419. # endif
  420. # elif defined(__370__) && defined(__IBMC__)
  421. # if defined(_LP64) || defined(_LARGE_FILES)
  422. # define SIZEOF_OFF_T 8
  423. # endif
  424. # endif
  425. # ifndef SIZEOF_OFF_T
  426. # define SIZEOF_OFF_T 4
  427. # endif
  428. #endif
  429. #if (SIZEOF_CURL_OFF_T < 8)
  430. #error "too small curl_off_t"
  431. #else
  432. /* assume SIZEOF_CURL_OFF_T == 8 */
  433. # define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
  434. #endif
  435. #define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - CURL_OFF_T_C(1))
  436. #if (SIZEOF_TIME_T == 4)
  437. # ifdef HAVE_TIME_T_UNSIGNED
  438. # define TIME_T_MAX UINT_MAX
  439. # define TIME_T_MIN 0
  440. # else
  441. # define TIME_T_MAX INT_MAX
  442. # define TIME_T_MIN INT_MIN
  443. # endif
  444. #else
  445. # ifdef HAVE_TIME_T_UNSIGNED
  446. # define TIME_T_MAX 0xFFFFFFFFFFFFFFFF
  447. # define TIME_T_MIN 0
  448. # else
  449. # define TIME_T_MAX 0x7FFFFFFFFFFFFFFF
  450. # define TIME_T_MIN (-TIME_T_MAX - 1)
  451. # endif
  452. #endif
  453. #ifndef SIZE_T_MAX
  454. /* some limits.h headers have this defined, some don't */
  455. #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
  456. #define SIZE_T_MAX 18446744073709551615U
  457. #else
  458. #define SIZE_T_MAX 4294967295U
  459. #endif
  460. #endif
  461. #ifndef SSIZE_T_MAX
  462. /* some limits.h headers have this defined, some don't */
  463. #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
  464. #define SSIZE_T_MAX 9223372036854775807
  465. #else
  466. #define SSIZE_T_MAX 2147483647
  467. #endif
  468. #endif
  469. /*
  470. * Arg 2 type for gethostname in case it hasn't been defined in config file.
  471. */
  472. #ifndef GETHOSTNAME_TYPE_ARG2
  473. # ifdef USE_WINSOCK
  474. # define GETHOSTNAME_TYPE_ARG2 int
  475. # else
  476. # define GETHOSTNAME_TYPE_ARG2 size_t
  477. # endif
  478. #endif
  479. /* Below we define some functions. They should
  480. 4. set the SIGALRM signal timeout
  481. 5. set dir/file naming defines
  482. */
  483. #ifdef _WIN32
  484. # define DIR_CHAR "\\"
  485. #else /* _WIN32 */
  486. # ifdef MSDOS /* Watt-32 */
  487. # include <sys/ioctl.h>
  488. # define select(n,r,w,x,t) select_s(n,r,w,x,t)
  489. # define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z))
  490. # include <tcp.h>
  491. # ifdef word
  492. # undef word
  493. # endif
  494. # ifdef byte
  495. # undef byte
  496. # endif
  497. # endif /* MSDOS */
  498. # ifdef __minix
  499. /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
  500. extern char *strtok_r(char *s, const char *delim, char **last);
  501. extern struct tm *gmtime_r(const time_t * const timep, struct tm *tmp);
  502. # endif
  503. # define DIR_CHAR "/"
  504. #endif /* _WIN32 */
  505. /* ---------------------------------------------------------------- */
  506. /* resolver specialty compile-time defines */
  507. /* CURLRES_* defines to use in the host*.c sources */
  508. /* ---------------------------------------------------------------- */
  509. /*
  510. * MSVC threads support requires a multi-threaded runtime library.
  511. * _beginthreadex() is not available in single-threaded ones.
  512. */
  513. #if defined(_MSC_VER) && !defined(_MT)
  514. # undef USE_THREADS_POSIX
  515. # undef USE_THREADS_WIN32
  516. #endif
  517. /*
  518. * Mutually exclusive CURLRES_* definitions.
  519. */
  520. #if defined(ENABLE_IPV6) && defined(HAVE_GETADDRINFO)
  521. # define CURLRES_IPV6
  522. #elif defined(ENABLE_IPV6) && (defined(_WIN32) || defined(__CYGWIN__))
  523. /* assume on Windows that IPv6 without getaddrinfo is a broken build */
  524. # error "Unexpected build: IPv6 is enabled but getaddrinfo was not found."
  525. #else
  526. # define CURLRES_IPV4
  527. #endif
  528. #ifdef USE_ARES
  529. # define CURLRES_ASYNCH
  530. # define CURLRES_ARES
  531. /* now undef the stock libc functions just to avoid them being used */
  532. # undef HAVE_GETADDRINFO
  533. # undef HAVE_FREEADDRINFO
  534. #elif defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
  535. # define CURLRES_ASYNCH
  536. # define CURLRES_THREADED
  537. #else
  538. # define CURLRES_SYNCH
  539. #endif
  540. /* ---------------------------------------------------------------- */
  541. #if defined(HAVE_LIBIDN2) && defined(HAVE_IDN2_H) && !defined(USE_WIN32_IDN)
  542. /* The lib and header are present */
  543. #define USE_LIBIDN2
  544. #endif
  545. #if defined(USE_LIBIDN2) && defined(USE_WIN32_IDN)
  546. #error "Both libidn2 and WinIDN are enabled, choose one."
  547. #endif
  548. #define LIBIDN_REQUIRED_VERSION "0.4.1"
  549. #if defined(USE_GNUTLS) || defined(USE_OPENSSL) || defined(USE_MBEDTLS) || \
  550. defined(USE_WOLFSSL) || defined(USE_SCHANNEL) || defined(USE_SECTRANSP) || \
  551. defined(USE_BEARSSL) || defined(USE_RUSTLS)
  552. #define USE_SSL /* SSL support has been enabled */
  553. #endif
  554. /* Single point where USE_SPNEGO definition might be defined */
  555. #if !defined(CURL_DISABLE_NEGOTIATE_AUTH) && \
  556. (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
  557. #define USE_SPNEGO
  558. #endif
  559. /* Single point where USE_KERBEROS5 definition might be defined */
  560. #if !defined(CURL_DISABLE_KERBEROS_AUTH) && \
  561. (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
  562. #define USE_KERBEROS5
  563. #endif
  564. /* Single point where USE_NTLM definition might be defined */
  565. #if !defined(CURL_DISABLE_NTLM)
  566. # if defined(USE_OPENSSL) || defined(USE_MBEDTLS) || \
  567. defined(USE_GNUTLS) || defined(USE_SECTRANSP) || \
  568. defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO) || \
  569. (defined(USE_WOLFSSL) && defined(HAVE_WOLFSSL_DES_ECB_ENCRYPT))
  570. # define USE_CURL_NTLM_CORE
  571. # endif
  572. # if defined(USE_CURL_NTLM_CORE) || defined(USE_WINDOWS_SSPI)
  573. # define USE_NTLM
  574. # endif
  575. #endif
  576. #ifdef CURL_WANTS_CA_BUNDLE_ENV
  577. #error "No longer supported. Set CURLOPT_CAINFO at runtime instead."
  578. #endif
  579. #if defined(USE_LIBSSH2) || defined(USE_LIBSSH) || defined(USE_WOLFSSH)
  580. #define USE_SSH
  581. #endif
  582. /*
  583. * Provide a mechanism to silence picky compilers, such as gcc 4.6+.
  584. * Parameters should of course normally not be unused, but for example when
  585. * we have multiple implementations of the same interface it may happen.
  586. */
  587. #if defined(__GNUC__) && ((__GNUC__ >= 3) || \
  588. ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 7)))
  589. # define UNUSED_PARAM __attribute__((__unused__))
  590. # define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  591. #else
  592. # define UNUSED_PARAM /* NOTHING */
  593. # define WARN_UNUSED_RESULT
  594. #endif
  595. /* noreturn attribute */
  596. #if !defined(CURL_NORETURN)
  597. #if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__clang__)
  598. # define CURL_NORETURN __attribute__((__noreturn__))
  599. #elif defined(_MSC_VER) && (_MSC_VER >= 1200)
  600. # define CURL_NORETURN __declspec(noreturn)
  601. #else
  602. # define CURL_NORETURN
  603. #endif
  604. #endif
  605. /* fallthrough attribute */
  606. #if !defined(FALLTHROUGH)
  607. #if (defined(__GNUC__) && __GNUC__ >= 7) || \
  608. (defined(__clang__) && __clang_major__ >= 10)
  609. # define FALLTHROUGH() __attribute__((fallthrough))
  610. #else
  611. # define FALLTHROUGH() do {} while (0)
  612. #endif
  613. #endif
  614. /*
  615. * Include macros and defines that should only be processed once.
  616. */
  617. #ifndef HEADER_CURL_SETUP_ONCE_H
  618. #include "curl_setup_once.h"
  619. #endif
  620. /*
  621. * Definition of our NOP statement Object-like macro
  622. */
  623. #ifndef Curl_nop_stmt
  624. # define Curl_nop_stmt do { } while(0)
  625. #endif
  626. /*
  627. * Ensure that Winsock and lwIP TCP/IP stacks are not mixed.
  628. */
  629. #if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)
  630. # if defined(SOCKET) || defined(USE_WINSOCK)
  631. # error "WinSock and lwIP TCP/IP stack definitions shall not coexist!"
  632. # endif
  633. #endif
  634. /*
  635. * shutdown() flags for systems that don't define them
  636. */
  637. #ifndef SHUT_RD
  638. #define SHUT_RD 0x00
  639. #endif
  640. #ifndef SHUT_WR
  641. #define SHUT_WR 0x01
  642. #endif
  643. #ifndef SHUT_RDWR
  644. #define SHUT_RDWR 0x02
  645. #endif
  646. /* Define S_ISREG if not defined by system headers, e.g. MSVC */
  647. #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
  648. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  649. #endif
  650. /* Define S_ISDIR if not defined by system headers, e.g. MSVC */
  651. #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
  652. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  653. #endif
  654. /* In Windows the default file mode is text but an application can override it.
  655. Therefore we specify it explicitly. https://github.com/curl/curl/pull/258
  656. */
  657. #if defined(_WIN32) || defined(MSDOS)
  658. #define FOPEN_READTEXT "rt"
  659. #define FOPEN_WRITETEXT "wt"
  660. #define FOPEN_APPENDTEXT "at"
  661. #elif defined(__CYGWIN__)
  662. /* Cygwin has specific behavior we need to address when WIN32 is not defined.
  663. https://cygwin.com/cygwin-ug-net/using-textbinary.html
  664. For write we want our output to have line endings of LF and be compatible with
  665. other Cygwin utilities. For read we want to handle input that may have line
  666. endings either CRLF or LF so 't' is appropriate.
  667. */
  668. #define FOPEN_READTEXT "rt"
  669. #define FOPEN_WRITETEXT "w"
  670. #define FOPEN_APPENDTEXT "a"
  671. #else
  672. #define FOPEN_READTEXT "r"
  673. #define FOPEN_WRITETEXT "w"
  674. #define FOPEN_APPENDTEXT "a"
  675. #endif
  676. /* for systems that don't detect this in configure */
  677. #ifndef CURL_SA_FAMILY_T
  678. # if defined(HAVE_SA_FAMILY_T)
  679. # define CURL_SA_FAMILY_T sa_family_t
  680. # elif defined(HAVE_ADDRESS_FAMILY)
  681. # define CURL_SA_FAMILY_T ADDRESS_FAMILY
  682. # else
  683. /* use a sensible default */
  684. # define CURL_SA_FAMILY_T unsigned short
  685. # endif
  686. #endif
  687. /* Some convenience macros to get the larger/smaller value out of two given.
  688. We prefix with CURL to prevent name collisions. */
  689. #define CURLMAX(x,y) ((x)>(y)?(x):(y))
  690. #define CURLMIN(x,y) ((x)<(y)?(x):(y))
  691. /* A convenience macro to provide both the string literal and the length of
  692. the string literal in one go, useful for functions that take "string,len"
  693. as their argument */
  694. #define STRCONST(x) x,sizeof(x)-1
  695. /* Some versions of the Android SDK is missing the declaration */
  696. #if defined(HAVE_GETPWUID_R) && defined(HAVE_DECL_GETPWUID_R_MISSING)
  697. struct passwd;
  698. int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf,
  699. size_t buflen, struct passwd **result);
  700. #endif
  701. #ifdef DEBUGBUILD
  702. #define UNITTEST
  703. #else
  704. #define UNITTEST static
  705. #endif
  706. /* Hyper supports HTTP2 also, but Curl's integration with Hyper does not */
  707. #if defined(USE_NGHTTP2)
  708. #define USE_HTTP2
  709. #endif
  710. #if (defined(USE_NGTCP2) && defined(USE_NGHTTP3)) || \
  711. (defined(USE_OPENSSL_QUIC) && defined(USE_NGHTTP3)) || \
  712. defined(USE_QUICHE) || defined(USE_MSH3)
  713. #ifdef CURL_WITH_MULTI_SSL
  714. #error "Multi-SSL combined with QUIC is not supported"
  715. #endif
  716. #define ENABLE_QUIC
  717. #define USE_HTTP3
  718. #endif
  719. /* Certain Windows implementations are not aligned with what curl expects,
  720. so always use the local one on this platform. E.g. the mingw-w64
  721. implementation can return wrong results for non-ASCII inputs. */
  722. #if defined(HAVE_BASENAME) && defined(_WIN32)
  723. #undef HAVE_BASENAME
  724. #endif
  725. #if defined(USE_UNIX_SOCKETS) && defined(_WIN32)
  726. # if !defined(UNIX_PATH_MAX)
  727. /* Replicating logic present in afunix.h
  728. (distributed with newer Windows 10 SDK versions only) */
  729. # define UNIX_PATH_MAX 108
  730. /* !checksrc! disable TYPEDEFSTRUCT 1 */
  731. typedef struct sockaddr_un {
  732. ADDRESS_FAMILY sun_family;
  733. char sun_path[UNIX_PATH_MAX];
  734. } SOCKADDR_UN, *PSOCKADDR_UN;
  735. # define WIN32_SOCKADDR_UN
  736. # endif
  737. #endif
  738. /* OpenSSLv3 marks DES, MD5 and ENGINE functions deprecated but we have no
  739. replacements (yet) so tell the compiler to not warn for them. */
  740. #ifdef USE_OPENSSL
  741. #define OPENSSL_SUPPRESS_DEPRECATED
  742. #endif
  743. #endif /* HEADER_CURL_SETUP_H */