curl_setup.h 26 KB

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