curl_setup.h 30 KB

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