curl_setup.h 28 KB

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