curl_setup.h 28 KB

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