curl_setup.h 24 KB

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