curl_setup.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  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) /* Keep this PP check separate from others */
  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. #if defined(__MINGW32__) && \
  74. (!defined(__MINGW64_VERSION_MAJOR) || (__MINGW64_VERSION_MAJOR < 3))
  75. #error "Building curl requires mingw-w64 3.0 or later"
  76. #endif
  77. /* Visual Studio 2010 is the minimum Visual Studio version we support.
  78. Workarounds for older versions of Visual Studio have been removed. */
  79. #if defined(_MSC_VER) && (_MSC_VER < 1600)
  80. #error "Ancient versions of Visual Studio are no longer supported due to bugs."
  81. #endif
  82. #ifdef _MSC_VER
  83. /* Disable Visual Studio warnings: 4127 "conditional expression is constant" */
  84. #pragma warning(disable:4127)
  85. /* Avoid VS2005 and upper complaining about portable C functions. */
  86. #ifndef _CRT_NONSTDC_NO_DEPRECATE /* mingw-w64 v2+. MS SDK ~10+/~VS2017+. */
  87. #define _CRT_NONSTDC_NO_DEPRECATE /* for close(), fileno(), unlink(), etc. */
  88. #endif
  89. #ifndef _CRT_SECURE_NO_WARNINGS
  90. #define _CRT_SECURE_NO_WARNINGS /* for getenv(), tests: sscanf() */
  91. #endif
  92. #endif /* _MSC_VER */
  93. #ifdef _WIN32
  94. /*
  95. * Do not include unneeded stuff in Windows headers to avoid compiler
  96. * warnings and macro clashes.
  97. * Make sure to define this macro before including any Windows headers.
  98. */
  99. # ifndef WIN32_LEAN_AND_MEAN
  100. # define WIN32_LEAN_AND_MEAN
  101. # endif
  102. # ifndef NOGDI
  103. # define NOGDI
  104. # endif
  105. /* Detect Windows App environment which has a restricted access
  106. * to the Win32 APIs. */
  107. # if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \
  108. defined(WINAPI_FAMILY)
  109. # include <winapifamily.h>
  110. # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
  111. !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
  112. # define CURL_WINDOWS_UWP
  113. # endif
  114. # endif
  115. #endif
  116. /* Compatibility */
  117. #ifdef ENABLE_IPV6
  118. #define USE_IPV6 1
  119. #endif
  120. /*
  121. * Include configuration script results or hand-crafted
  122. * configuration file for platforms which lack config tool.
  123. */
  124. #ifdef HAVE_CONFIG_H
  125. #include "curl_config.h"
  126. #else /* HAVE_CONFIG_H */
  127. #ifdef _WIN32
  128. # include "config-win32.h"
  129. #endif
  130. #ifdef macintosh
  131. # include "config-mac.h"
  132. #endif
  133. #ifdef __riscos__
  134. # include "config-riscos.h"
  135. #endif
  136. #ifdef __OS400__
  137. # include "config-os400.h"
  138. #endif
  139. #ifdef __PLAN9__
  140. # include "config-plan9.h"
  141. #endif
  142. #endif /* HAVE_CONFIG_H */
  143. /* ================================================================ */
  144. /* Definition of preprocessor macros/symbols which modify compiler */
  145. /* behavior or generated code characteristics must be done here, */
  146. /* as appropriate, before any system header file is included. It is */
  147. /* also possible to have them defined in the config file included */
  148. /* before this point. As a result of all this we frown inclusion of */
  149. /* system header files in our config files, avoid this at any cost. */
  150. /* ================================================================ */
  151. #ifdef HAVE_LIBZ
  152. # ifndef ZLIB_CONST
  153. # define ZLIB_CONST /* Use z_const. Supported by v1.2.5.2 and upper. */
  154. # endif
  155. #endif
  156. /*
  157. * AIX 4.3 and newer needs _THREAD_SAFE defined to build
  158. * proper reentrant code. Others may also need it.
  159. */
  160. #ifdef NEED_THREAD_SAFE
  161. # ifndef _THREAD_SAFE
  162. # define _THREAD_SAFE
  163. # endif
  164. #endif
  165. /*
  166. * Tru64 needs _REENTRANT set for a few function prototypes and
  167. * things to appear in the system header files. Unixware needs it
  168. * to build proper reentrant code. Others may also need it.
  169. */
  170. #ifdef NEED_REENTRANT
  171. # ifndef _REENTRANT
  172. # define _REENTRANT
  173. # endif
  174. #endif
  175. /* Solaris needs this to get a POSIX-conformant getpwuid_r */
  176. #if defined(sun) || defined(__sun)
  177. # ifndef _POSIX_PTHREAD_SEMANTICS
  178. # define _POSIX_PTHREAD_SEMANTICS 1
  179. # endif
  180. #endif
  181. /* ================================================================ */
  182. /* If you need to include a system header file for your platform, */
  183. /* please, do it beyond the point further indicated in this file. */
  184. /* ================================================================ */
  185. /* Give calloc a chance to be dragging in early, so we do not redefine */
  186. #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
  187. # include <pthread.h>
  188. #endif
  189. /*
  190. * Disable other protocols when http is the only one desired.
  191. */
  192. #ifdef HTTP_ONLY
  193. # ifndef CURL_DISABLE_DICT
  194. # define CURL_DISABLE_DICT
  195. # endif
  196. # ifndef CURL_DISABLE_FILE
  197. # define CURL_DISABLE_FILE
  198. # endif
  199. # ifndef CURL_DISABLE_FTP
  200. # define CURL_DISABLE_FTP
  201. # endif
  202. # ifndef CURL_DISABLE_GOPHER
  203. # define CURL_DISABLE_GOPHER
  204. # endif
  205. # ifndef CURL_DISABLE_IMAP
  206. # define CURL_DISABLE_IMAP
  207. # endif
  208. # ifndef CURL_DISABLE_LDAP
  209. # define CURL_DISABLE_LDAP
  210. # endif
  211. # ifndef CURL_DISABLE_LDAPS
  212. # define CURL_DISABLE_LDAPS
  213. # endif
  214. # ifndef CURL_DISABLE_MQTT
  215. # define CURL_DISABLE_MQTT
  216. # endif
  217. # ifndef CURL_DISABLE_POP3
  218. # define CURL_DISABLE_POP3
  219. # endif
  220. # ifndef CURL_DISABLE_RTSP
  221. # define CURL_DISABLE_RTSP
  222. # endif
  223. # ifndef CURL_DISABLE_SMB
  224. # define CURL_DISABLE_SMB
  225. # endif
  226. # ifndef CURL_DISABLE_SMTP
  227. # define CURL_DISABLE_SMTP
  228. # endif
  229. # ifndef CURL_DISABLE_TELNET
  230. # define CURL_DISABLE_TELNET
  231. # endif
  232. # ifndef CURL_DISABLE_TFTP
  233. # define CURL_DISABLE_TFTP
  234. # endif
  235. #endif
  236. /*
  237. * When http is disabled rtsp is not supported.
  238. */
  239. #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP)
  240. # define CURL_DISABLE_RTSP
  241. #endif
  242. /*
  243. * When HTTP is disabled, disable HTTP-only features
  244. */
  245. #ifdef CURL_DISABLE_HTTP
  246. # define CURL_DISABLE_ALTSVC 1
  247. # define CURL_DISABLE_COOKIES 1
  248. # define CURL_DISABLE_BASIC_AUTH 1
  249. # define CURL_DISABLE_BEARER_AUTH 1
  250. # define CURL_DISABLE_AWS 1
  251. # define CURL_DISABLE_DOH 1
  252. # define CURL_DISABLE_FORM_API 1
  253. # define CURL_DISABLE_HEADERS_API 1
  254. # define CURL_DISABLE_HSTS 1
  255. # define CURL_DISABLE_HTTP_AUTH 1
  256. #endif
  257. /* ================================================================ */
  258. /* No system header file shall be included in this file before this */
  259. /* point. */
  260. /* ================================================================ */
  261. /*
  262. * OS/400 setup file includes some system headers.
  263. */
  264. #ifdef __OS400__
  265. # include "setup-os400.h"
  266. #endif
  267. /*
  268. * VMS setup file includes some system headers.
  269. */
  270. #ifdef __VMS
  271. # include "setup-vms.h"
  272. #endif
  273. /*
  274. * Windows setup file includes some system headers.
  275. */
  276. #ifdef _WIN32
  277. # include "setup-win32.h"
  278. #endif
  279. #include <curl/system.h>
  280. /* Helper macro to expand and concatenate two macros.
  281. * Direct macros concatenation does not work because macros
  282. * are not expanded before direct concatenation.
  283. */
  284. #define CURL_CONC_MACROS_(A, B) A ## B
  285. #define CURL_CONC_MACROS(A, B) CURL_CONC_MACROS_(A, B)
  286. /* curl uses its own printf() function internally. It understands the GNU
  287. * format. Use this format, so that it matches the GNU format attribute we
  288. * use with the MinGW compiler, allowing it to verify them at compile-time.
  289. */
  290. #ifdef __MINGW32__
  291. # undef CURL_FORMAT_CURL_OFF_T
  292. # undef CURL_FORMAT_CURL_OFF_TU
  293. # define CURL_FORMAT_CURL_OFF_T "lld"
  294. # define CURL_FORMAT_CURL_OFF_TU "llu"
  295. #endif
  296. /* based on logic in "curl/mprintf.h" */
  297. #if (defined(__GNUC__) || defined(__clang__) || \
  298. defined(__IAR_SYSTEMS_ICC__)) && \
  299. defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
  300. !defined(CURL_NO_FMT_CHECKS)
  301. #if defined(__MINGW32__) && !defined(__clang__)
  302. #define CURL_PRINTF(fmt, arg) \
  303. __attribute__((format(gnu_printf, fmt, arg)))
  304. #else
  305. #define CURL_PRINTF(fmt, arg) \
  306. __attribute__((format(__printf__, fmt, arg)))
  307. #endif
  308. #else
  309. #define CURL_PRINTF(fmt, arg)
  310. #endif
  311. /* Override default printf mask check rules in "curl/mprintf.h" */
  312. #define CURL_TEMP_PRINTF CURL_PRINTF
  313. /* Workaround for mainline llvm v16 and earlier missing a built-in macro
  314. expected by macOS SDK v14 / Xcode v15 (2023) and newer.
  315. gcc (as of v14) is also missing it. */
  316. #if defined(__APPLE__) && \
  317. ((!defined(__apple_build_version__) && \
  318. defined(__clang__) && __clang_major__ < 17) || \
  319. (defined(__GNUC__) && __GNUC__ <= 14)) && \
  320. defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
  321. !defined(__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__)
  322. #define __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ \
  323. __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
  324. #endif
  325. /*
  326. * Use getaddrinfo to resolve the IPv4 address literal. If the current network
  327. * interface does not support IPv4, but supports IPv6, NAT64, and DNS64,
  328. * performing this task will result in a synthesized IPv6 address.
  329. */
  330. #if defined(__APPLE__) && !defined(USE_ARES)
  331. # define USE_RESOLVE_ON_IPS 1
  332. # if TARGET_OS_MAC && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && \
  333. defined(USE_IPV6)
  334. # define CURL_MACOS_CALL_COPYPROXIES 1
  335. # endif
  336. #endif
  337. #ifdef USE_ARES
  338. # ifndef CARES_NO_DEPRECATED
  339. # define CARES_NO_DEPRECATED /* for ares_getsock() */
  340. # endif
  341. # if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && defined(_WIN32)
  342. # define CARES_STATICLIB /* define it before including ares.h */
  343. # endif
  344. #endif
  345. #ifdef USE_LWIPSOCK
  346. # include <lwip/init.h>
  347. # include <lwip/sockets.h>
  348. # include <lwip/netdb.h>
  349. #endif
  350. #ifdef macintosh
  351. # include <extra/stricmp.h>
  352. # include <extra/strdup.h>
  353. #endif
  354. #ifdef __AMIGA__
  355. # ifdef __amigaos4__
  356. # define __USE_INLINE__
  357. /* use our own resolver which uses runtime feature detection */
  358. # define CURLRES_AMIGA
  359. /* getaddrinfo() currently crashes bsdsocket.library, so disable */
  360. # undef HAVE_GETADDRINFO
  361. # if !(defined(__NEWLIB__) || \
  362. (defined(__CLIB2__) && defined(__THREAD_SAFE)))
  363. /* disable threaded resolver with clib2 - requires newlib or clib-ts */
  364. # undef USE_THREADS_POSIX
  365. # endif
  366. # endif
  367. # include <exec/types.h>
  368. # include <exec/execbase.h>
  369. # include <proto/exec.h>
  370. # include <proto/dos.h>
  371. # include <unistd.h>
  372. # if defined(HAVE_PROTO_BSDSOCKET_H) && \
  373. (!defined(__amigaos4__) || defined(USE_AMISSL))
  374. /* use bsdsocket.library directly, instead of libc networking functions */
  375. # define _SYS_MBUF_H /* m_len define clashes with curl */
  376. # include <proto/bsdsocket.h>
  377. # ifdef __amigaos4__
  378. int Curl_amiga_select(int nfds, fd_set *readfds, fd_set *writefds,
  379. fd_set *errorfds, struct timeval *timeout);
  380. # define select(a, b, c, d, e) Curl_amiga_select(a, b, c, d, e)
  381. # else
  382. # define select(a, b, c, d, e) WaitSelect(a, b, c, d, e, 0)
  383. # endif
  384. /* must not use libc's fcntl() on bsdsocket.library sockfds! */
  385. # undef HAVE_FCNTL
  386. # undef HAVE_FCNTL_O_NONBLOCK
  387. # else
  388. /* use libc networking and hence close() and fnctl() */
  389. # undef HAVE_CLOSESOCKET_CAMEL
  390. # undef HAVE_IOCTLSOCKET_CAMEL
  391. # endif
  392. /*
  393. * In clib2 arpa/inet.h warns that some prototypes may clash
  394. * with bsdsocket.library. This avoids the definition of those.
  395. */
  396. # define __NO_NET_API
  397. #endif
  398. /* Whether to use eventfd() */
  399. #if defined(HAVE_EVENTFD) && defined(HAVE_SYS_EVENTFD_H)
  400. #define USE_EVENTFD
  401. #endif
  402. #include <stdio.h>
  403. #include <assert.h>
  404. #ifdef __TANDEM /* for ns*-tandem-nsk systems */
  405. # ifndef __LP64
  406. # include <floss.h> /* FLOSS is only used for 32-bit builds. */
  407. # endif
  408. #endif
  409. #ifndef STDC_HEADERS /* no standard C headers! */
  410. #include <curl/stdcheaders.h>
  411. #endif
  412. #if defined(HAVE_STDINT_H) || defined(USE_WOLFSSL)
  413. #include <stdint.h>
  414. #endif
  415. #include <limits.h>
  416. #ifdef _WIN32
  417. # ifdef HAVE_IO_H
  418. # include <io.h>
  419. # endif
  420. # include <sys/types.h>
  421. # include <sys/stat.h>
  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. # define struct_stat struct _stati64
  428. # define LSEEK_ERROR (__int64)-1
  429. #elif defined(__DJGPP__)
  430. /* Requires DJGPP 2.04 */
  431. # include <unistd.h>
  432. # undef lseek
  433. # define lseek(fdes, offset, whence) llseek(fdes, offset, whence)
  434. # define LSEEK_ERROR (offset_t)-1
  435. #endif
  436. #ifndef struct_stat
  437. #define struct_stat struct stat
  438. #endif
  439. #ifndef LSEEK_ERROR
  440. #define LSEEK_ERROR (off_t)-1
  441. #endif
  442. #ifndef SIZEOF_TIME_T
  443. /* assume default size of time_t to be 32 bits */
  444. #define SIZEOF_TIME_T 4
  445. #endif
  446. #ifndef SIZEOF_CURL_SOCKET_T
  447. /* configure and cmake check and set the define */
  448. # ifdef _WIN64
  449. # define SIZEOF_CURL_SOCKET_T 8
  450. # else
  451. /* default guess */
  452. # define SIZEOF_CURL_SOCKET_T 4
  453. # endif
  454. #endif
  455. #if SIZEOF_CURL_SOCKET_T < 8
  456. #ifdef _WIN32
  457. # define FMT_SOCKET_T "u"
  458. #else
  459. # define FMT_SOCKET_T "d"
  460. #endif
  461. #elif defined(_WIN32)
  462. # define FMT_SOCKET_T "zu"
  463. #else
  464. # define FMT_SOCKET_T "qd"
  465. #endif
  466. /*
  467. * Default sizeof(off_t) in case it has not been defined in config file.
  468. */
  469. #ifndef SIZEOF_OFF_T
  470. # if defined(__VMS) && !defined(__VAX)
  471. # ifdef _LARGEFILE
  472. # define SIZEOF_OFF_T 8
  473. # endif
  474. # elif defined(__OS400__) && defined(__ILEC400__)
  475. # ifdef _LARGE_FILES
  476. # define SIZEOF_OFF_T 8
  477. # endif
  478. # elif defined(__MVS__) && defined(__IBMC__)
  479. # if defined(_LP64) || defined(_LARGE_FILES)
  480. # define SIZEOF_OFF_T 8
  481. # endif
  482. # elif defined(__370__) && defined(__IBMC__)
  483. # if defined(_LP64) || defined(_LARGE_FILES)
  484. # define SIZEOF_OFF_T 8
  485. # endif
  486. # endif
  487. # ifndef SIZEOF_OFF_T
  488. # define SIZEOF_OFF_T 4
  489. # endif
  490. #endif
  491. #if (SIZEOF_CURL_OFF_T < 8)
  492. #error "too small curl_off_t"
  493. #else
  494. /* assume SIZEOF_CURL_OFF_T == 8 */
  495. # define CURL_OFF_T_MAX 0x7FFFFFFFFFFFFFFF
  496. #endif
  497. #define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - 1)
  498. #define FMT_OFF_T CURL_FORMAT_CURL_OFF_T
  499. #define FMT_OFF_TU CURL_FORMAT_CURL_OFF_TU
  500. #if (SIZEOF_TIME_T == 4)
  501. # ifdef HAVE_TIME_T_UNSIGNED
  502. # define TIME_T_MAX UINT_MAX
  503. # define TIME_T_MIN 0
  504. # else
  505. # define TIME_T_MAX INT_MAX
  506. # define TIME_T_MIN INT_MIN
  507. # endif
  508. #else
  509. # ifdef HAVE_TIME_T_UNSIGNED
  510. # define TIME_T_MAX 0xFFFFFFFFFFFFFFFF
  511. # define TIME_T_MIN 0
  512. # else
  513. # define TIME_T_MAX 0x7FFFFFFFFFFFFFFF
  514. # define TIME_T_MIN (-TIME_T_MAX - 1)
  515. # endif
  516. #endif
  517. #ifndef SIZE_MAX
  518. /* some limits.h headers have this defined, some do not */
  519. #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
  520. #define SIZE_MAX 18446744073709551615U
  521. #else
  522. #define SIZE_MAX 4294967295U
  523. #endif
  524. #endif
  525. #ifndef SSIZE_MAX
  526. /* some limits.h headers have this defined, some do not */
  527. #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
  528. #define SSIZE_MAX 9223372036854775807
  529. #else
  530. #define SSIZE_MAX 2147483647
  531. #endif
  532. #endif
  533. #if SIZEOF_LONG > SIZEOF_SIZE_T
  534. #error "unexpected: 'long' is larger than 'size_t'"
  535. #endif
  536. /*
  537. * Arg 2 type for gethostname in case it has not been defined in config file.
  538. */
  539. #ifndef GETHOSTNAME_TYPE_ARG2
  540. # ifdef USE_WINSOCK
  541. # define GETHOSTNAME_TYPE_ARG2 int
  542. # else
  543. # define GETHOSTNAME_TYPE_ARG2 size_t
  544. # endif
  545. #endif
  546. /* Below we define some functions. They should
  547. 4. set the SIGALRM signal timeout
  548. 5. set dir/file naming defines
  549. */
  550. #ifdef _WIN32
  551. # define DIR_CHAR "\\"
  552. #else /* _WIN32 */
  553. # ifdef MSDOS /* Watt-32 */
  554. # include <sys/ioctl.h>
  555. # define select(n, r, w, x, t) select_s(n, r, w, x, t)
  556. # define ioctl(x, y, z) ioctlsocket(x, y, (char *)(z))
  557. # include <tcp.h>
  558. # undef word
  559. # undef byte
  560. # endif /* MSDOS */
  561. # ifdef __minix
  562. /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
  563. extern struct tm *gmtime_r(const time_t * const timep, struct tm *tmp);
  564. # endif
  565. # define DIR_CHAR "/"
  566. #endif /* _WIN32 */
  567. /* ---------------------------------------------------------------- */
  568. /* resolver specialty compile-time defines */
  569. /* CURLRES_* defines to use in the host*.c sources */
  570. /* ---------------------------------------------------------------- */
  571. /*
  572. * Mutually exclusive CURLRES_* definitions.
  573. */
  574. #if defined(USE_IPV6) && defined(HAVE_GETADDRINFO)
  575. # define CURLRES_IPV6
  576. #elif defined(USE_IPV6) && (defined(_WIN32) || defined(__CYGWIN__))
  577. /* assume on Windows that IPv6 without getaddrinfo is a broken build */
  578. # error "Unexpected build: IPv6 is enabled but getaddrinfo was not found."
  579. #else
  580. # define CURLRES_IPV4
  581. #endif
  582. #if defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
  583. # define CURLRES_ASYNCH
  584. # define CURLRES_THREADED
  585. #elif defined(USE_ARES)
  586. # define CURLRES_ASYNCH
  587. # define CURLRES_ARES
  588. /* now undef the stock libc functions just to avoid them being used */
  589. # undef HAVE_GETADDRINFO
  590. # undef HAVE_FREEADDRINFO
  591. #else
  592. # define CURLRES_SYNCH
  593. #endif
  594. /* ---------------------------------------------------------------- */
  595. #if defined(HAVE_LIBIDN2) && defined(HAVE_IDN2_H) && \
  596. !defined(USE_WIN32_IDN) && !defined(USE_APPLE_IDN)
  597. /* The lib and header are present */
  598. #define USE_LIBIDN2
  599. #endif
  600. #if defined(USE_LIBIDN2) && (defined(USE_WIN32_IDN) || defined(USE_APPLE_IDN))
  601. #error "libidn2 cannot be enabled with WinIDN or AppleIDN, choose one."
  602. #endif
  603. #if defined(USE_GNUTLS) || defined(USE_OPENSSL) || defined(USE_MBEDTLS) || \
  604. defined(USE_WOLFSSL) || defined(USE_SCHANNEL) || \
  605. defined(USE_RUSTLS)
  606. #define USE_SSL /* SSL support has been enabled */
  607. #endif
  608. #if defined(USE_OPENSSL) && defined(USE_WOLFSSL)
  609. # include <wolfssl/version.h>
  610. # if LIBWOLFSSL_VERSION_HEX >= 0x05007006
  611. # ifndef OPENSSL_COEXIST
  612. # define OPENSSL_COEXIST
  613. # endif
  614. # else
  615. # error "OpenSSL can only coexist with wolfSSL v5.7.6 or upper"
  616. # endif
  617. #endif
  618. #if defined(USE_WOLFSSL) && defined(USE_GNUTLS)
  619. /* Avoid defining unprefixed wolfSSL SHA macros colliding with nettle ones */
  620. #define NO_OLD_WC_NAMES
  621. #endif
  622. /* Single point where USE_SPNEGO definition might be defined */
  623. #if !defined(CURL_DISABLE_NEGOTIATE_AUTH) && \
  624. (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
  625. #define USE_SPNEGO
  626. #endif
  627. /* Single point where USE_KERBEROS5 definition might be defined */
  628. #if !defined(CURL_DISABLE_KERBEROS_AUTH) && \
  629. (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
  630. #define USE_KERBEROS5
  631. #endif
  632. /* Single point where USE_NTLM definition might be defined */
  633. #ifndef CURL_DISABLE_NTLM
  634. # if (defined(USE_OPENSSL) && defined(HAVE_DES_ECB_ENCRYPT)) || \
  635. defined(USE_GNUTLS) || \
  636. (defined(USE_MBEDTLS) && defined(HAVE_MBEDTLS_DES_CRYPT_ECB)) || \
  637. defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO) || \
  638. (defined(USE_WOLFSSL) && defined(HAVE_WOLFSSL_DES_ECB_ENCRYPT))
  639. # define USE_CURL_NTLM_CORE
  640. # endif
  641. # if defined(USE_CURL_NTLM_CORE) || defined(USE_WINDOWS_SSPI)
  642. # define USE_NTLM
  643. # endif
  644. #endif
  645. #if defined(USE_LIBSSH2) || defined(USE_LIBSSH)
  646. #define USE_SSH
  647. #endif
  648. /*
  649. * Provide a mechanism to silence picky compilers, such as gcc 4.6+.
  650. * Parameters should of course normally not be unused, but for example when
  651. * we have multiple implementations of the same interface it may happen.
  652. */
  653. #if defined(__GNUC__) && ((__GNUC__ >= 3) || \
  654. ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 7)))
  655. # define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  656. #elif defined(__IAR_SYSTEMS_ICC__) && (__VER__ >= 9040001)
  657. # define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  658. #else
  659. # define WARN_UNUSED_RESULT
  660. #endif
  661. /* noreturn attribute */
  662. #ifndef CURL_NORETURN
  663. #if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__clang__) || \
  664. defined(__IAR_SYSTEMS_ICC__)
  665. # define CURL_NORETURN __attribute__((__noreturn__))
  666. #elif defined(_MSC_VER)
  667. # define CURL_NORETURN __declspec(noreturn)
  668. #else
  669. # define CURL_NORETURN
  670. #endif
  671. #endif
  672. /* fallthrough attribute */
  673. #ifndef FALLTHROUGH
  674. #if (defined(__GNUC__) && __GNUC__ >= 7) || \
  675. (defined(__clang__) && __clang_major__ >= 10)
  676. # define FALLTHROUGH() __attribute__((fallthrough))
  677. #else
  678. # define FALLTHROUGH() do {} while (0)
  679. #endif
  680. #endif
  681. /*
  682. * Include macros and defines that should only be processed once.
  683. */
  684. #ifndef HEADER_CURL_SETUP_ONCE_H
  685. #include "curl_setup_once.h"
  686. #endif
  687. /*
  688. * Macros and functions to safely suppress warnings
  689. */
  690. #include "curlx/warnless.h"
  691. #ifdef _WIN32
  692. # undef read
  693. # define read(fd, buf, count) (ssize_t)_read(fd, buf, curlx_uztoui(count))
  694. # undef write
  695. # define write(fd, buf, count) (ssize_t)_write(fd, buf, curlx_uztoui(count))
  696. #endif
  697. /*
  698. * Definition of our NOP statement Object-like macro
  699. */
  700. #ifndef Curl_nop_stmt
  701. #define Curl_nop_stmt do {} while(0)
  702. #endif
  703. /*
  704. * Ensure that Winsock and lwIP TCP/IP stacks are not mixed.
  705. */
  706. #if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)
  707. # if defined(SOCKET) || defined(USE_WINSOCK)
  708. # error "Winsock and lwIP TCP/IP stack definitions shall not coexist!"
  709. # endif
  710. #endif
  711. /*
  712. * shutdown() flags for systems that do not define them
  713. */
  714. #ifndef SHUT_RD
  715. #define SHUT_RD 0x00
  716. #endif
  717. #ifndef SHUT_WR
  718. #define SHUT_WR 0x01
  719. #endif
  720. #ifndef SHUT_RDWR
  721. #define SHUT_RDWR 0x02
  722. #endif
  723. /* Define S_ISREG if not defined by system headers, e.g. MSVC */
  724. #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
  725. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  726. #endif
  727. /* Define S_ISDIR if not defined by system headers, e.g. MSVC */
  728. #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
  729. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  730. #endif
  731. /* For MSVC (all versions as of VS2022) */
  732. #ifndef STDIN_FILENO
  733. #define STDIN_FILENO fileno(stdin)
  734. #endif
  735. #ifndef STDOUT_FILENO
  736. #define STDOUT_FILENO fileno(stdout)
  737. #endif
  738. #ifndef STDERR_FILENO
  739. #define STDERR_FILENO fileno(stderr)
  740. #endif
  741. /* Since O_BINARY is used in bitmasks, setting it to zero makes it usable in
  742. source code but yet it does not ruin anything */
  743. #ifdef O_BINARY
  744. #define CURL_O_BINARY O_BINARY
  745. #else
  746. #define CURL_O_BINARY 0
  747. #endif
  748. /* In Windows the default file mode is text but an application can override it.
  749. Therefore we specify it explicitly. https://github.com/curl/curl/pull/258
  750. */
  751. #if defined(_WIN32) || defined(MSDOS)
  752. #define FOPEN_READTEXT "rt"
  753. #define FOPEN_WRITETEXT "wt"
  754. #define FOPEN_APPENDTEXT "at"
  755. #elif defined(__CYGWIN__)
  756. /* Cygwin has specific behavior we need to address when _WIN32 is not defined.
  757. https://cygwin.com/cygwin-ug-net/using-textbinary.html
  758. For write we want our output to have line endings of LF and be compatible with
  759. other Cygwin utilities. For read we want to handle input that may have line
  760. endings either CRLF or LF so 't' is appropriate.
  761. */
  762. #define FOPEN_READTEXT "rt"
  763. #define FOPEN_WRITETEXT "w"
  764. #define FOPEN_APPENDTEXT "a"
  765. #else
  766. #define FOPEN_READTEXT "r"
  767. #define FOPEN_WRITETEXT "w"
  768. #define FOPEN_APPENDTEXT "a"
  769. #endif
  770. /* for systems that do not detect this in configure */
  771. #ifndef CURL_SA_FAMILY_T
  772. # ifdef _WIN32
  773. # define CURL_SA_FAMILY_T ADDRESS_FAMILY
  774. # elif defined(HAVE_SA_FAMILY_T)
  775. # define CURL_SA_FAMILY_T sa_family_t
  776. # elif defined(__AMIGA__)
  777. # define CURL_SA_FAMILY_T unsigned char
  778. # else
  779. /* use a sensible default */
  780. # define CURL_SA_FAMILY_T unsigned short
  781. # endif
  782. #endif
  783. /* Some convenience macros to get the larger/smaller value out of two given.
  784. We prefix with CURL to prevent name collisions. */
  785. #define CURLMAX(x, y) ((x) > (y) ? (x) : (y))
  786. #define CURLMIN(x, y) ((x) < (y) ? (x) : (y))
  787. /* A convenience macro to provide both the string literal and the length of
  788. the string literal in one go, useful for functions that take "string,len"
  789. as their argument */
  790. #define STRCONST(x) x, sizeof(x) - 1
  791. #define CURL_ARRAYSIZE(A) (sizeof(A) / sizeof((A)[0]))
  792. /* Buffer size for error messages retrieved via
  793. curlx_strerror() and Curl_sspi_strerror() */
  794. #define STRERROR_LEN 256
  795. #ifndef CURL_DID_MEMORY_FUNC_TYPEDEFS /* only if not already done */
  796. /*
  797. * The following memory function replacement typedef's are COPIED from
  798. * curl/curl.h and MUST match the originals. We copy them to avoid having to
  799. * include curl/curl.h here. We avoid that include since it includes stdio.h
  800. * and other headers that may get messed up with defines done here.
  801. */
  802. typedef void *(*curl_malloc_callback)(size_t size);
  803. typedef void (*curl_free_callback)(void *ptr);
  804. typedef void *(*curl_realloc_callback)(void *ptr, size_t size);
  805. typedef char *(*curl_strdup_callback)(const char *str);
  806. typedef void *(*curl_calloc_callback)(size_t nmemb, size_t size);
  807. #define CURL_DID_MEMORY_FUNC_TYPEDEFS
  808. #endif
  809. extern curl_malloc_callback Curl_cmalloc;
  810. extern curl_free_callback Curl_cfree;
  811. extern curl_realloc_callback Curl_crealloc;
  812. extern curl_strdup_callback Curl_cstrdup;
  813. extern curl_calloc_callback Curl_ccalloc;
  814. /*
  815. * Curl_safefree defined as a macro to allow MemoryTracking feature
  816. * to log free() calls at same location where Curl_safefree is used.
  817. * This macro also assigns NULL to given pointer when free'd.
  818. */
  819. #define Curl_safefree(ptr) \
  820. do { \
  821. curlx_free(ptr); \
  822. (ptr) = NULL; \
  823. } while(0)
  824. #include <curl/curl.h> /* for CURL_EXTERN, curl_socket_t, mprintf.h */
  825. #ifdef CURLDEBUG
  826. #ifdef __clang__
  827. # define ALLOC_FUNC __attribute__((__malloc__))
  828. # if __clang_major__ >= 4
  829. # define ALLOC_SIZE(s) __attribute__((__alloc_size__(s)))
  830. # define ALLOC_SIZE2(n, s) __attribute__((__alloc_size__(n, s)))
  831. # else
  832. # define ALLOC_SIZE(s)
  833. # define ALLOC_SIZE2(n, s)
  834. # endif
  835. #elif defined(__GNUC__) && __GNUC__ >= 3
  836. # define ALLOC_FUNC __attribute__((__malloc__))
  837. # define ALLOC_SIZE(s) __attribute__((__alloc_size__(s)))
  838. # define ALLOC_SIZE2(n, s) __attribute__((__alloc_size__(n, s)))
  839. #elif defined(_MSC_VER)
  840. # define ALLOC_FUNC __declspec(restrict)
  841. # define ALLOC_SIZE(s)
  842. # define ALLOC_SIZE2(n, s)
  843. #else
  844. # define ALLOC_FUNC
  845. # define ALLOC_SIZE(s)
  846. # define ALLOC_SIZE2(n, s)
  847. #endif
  848. extern FILE *curl_dbg_logfile;
  849. /* memory functions */
  850. CURL_EXTERN void curl_dbg_free(void *ptr, int line, const char *source);
  851. CURL_EXTERN ALLOC_FUNC ALLOC_SIZE(1)
  852. void *curl_dbg_malloc(size_t size, int line, const char *source);
  853. CURL_EXTERN ALLOC_FUNC ALLOC_SIZE2(1, 2)
  854. void *curl_dbg_calloc(size_t n, size_t size, int line, const char *source);
  855. CURL_EXTERN ALLOC_SIZE(2)
  856. void *curl_dbg_realloc(void *ptr, size_t size, int line, const char *source);
  857. CURL_EXTERN ALLOC_FUNC
  858. char *curl_dbg_strdup(const char *str, int line, const char *src);
  859. #if defined(_WIN32) && defined(UNICODE)
  860. CURL_EXTERN ALLOC_FUNC
  861. wchar_t *curl_dbg_wcsdup(const wchar_t *str, int line, const char *source);
  862. #endif
  863. CURL_EXTERN void curl_dbg_memdebug(const char *logname);
  864. CURL_EXTERN void curl_dbg_memlimit(long limit);
  865. CURL_EXTERN void curl_dbg_log(const char *format, ...) CURL_PRINTF(1, 2);
  866. /* file descriptor manipulators */
  867. CURL_EXTERN curl_socket_t curl_dbg_socket(int domain, int type, int protocol,
  868. int line, const char *source);
  869. CURL_EXTERN void curl_dbg_mark_sclose(curl_socket_t sockfd,
  870. int line, const char *source);
  871. CURL_EXTERN int curl_dbg_sclose(curl_socket_t sockfd,
  872. int line, const char *source);
  873. CURL_EXTERN curl_socket_t curl_dbg_accept(curl_socket_t s, void *a, void *alen,
  874. int line, const char *source);
  875. #ifdef HAVE_ACCEPT4
  876. CURL_EXTERN curl_socket_t curl_dbg_accept4(curl_socket_t s, void *saddr,
  877. void *saddrlen, int flags,
  878. int line, const char *source);
  879. #endif
  880. #ifdef HAVE_SOCKETPAIR
  881. CURL_EXTERN int curl_dbg_socketpair(int domain, int type, int protocol,
  882. curl_socket_t socket_vector[2],
  883. int line, const char *source);
  884. #endif
  885. /* FILE functions */
  886. CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
  887. CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fopen(const char *file, const char *mode,
  888. int line, const char *source);
  889. CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_freopen(const char *file,
  890. const char *mode, FILE *fh,
  891. int line, const char *source);
  892. CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode,
  893. int line, const char *source);
  894. #define sclose(sockfd) curl_dbg_sclose(sockfd, __LINE__, __FILE__)
  895. #define fake_sclose(sockfd) curl_dbg_mark_sclose(sockfd, __LINE__, __FILE__)
  896. #define CURL_GETADDRINFO(host, serv, hint, res) \
  897. curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
  898. #define CURL_FREEADDRINFO(data) \
  899. curl_dbg_freeaddrinfo(data, __LINE__, __FILE__)
  900. #define CURL_SOCKET(domain, type, protocol) \
  901. curl_dbg_socket((int)domain, type, protocol, __LINE__, __FILE__)
  902. #ifdef HAVE_SOCKETPAIR
  903. #define CURL_SOCKETPAIR(domain, type, protocol, socket_vector) \
  904. curl_dbg_socketpair((int)domain, type, protocol, socket_vector, \
  905. __LINE__, __FILE__)
  906. #endif
  907. #define CURL_ACCEPT(sock, addr, len) \
  908. curl_dbg_accept(sock, addr, len, __LINE__, __FILE__)
  909. #ifdef HAVE_ACCEPT4
  910. #define CURL_ACCEPT4(sock, addr, len, flags) \
  911. curl_dbg_accept4(sock, addr, len, flags, __LINE__, __FILE__)
  912. #endif
  913. #else /* !CURLDEBUG */
  914. #define sclose(x) CURL_SCLOSE(x)
  915. #define fake_sclose(x) Curl_nop_stmt
  916. #define CURL_GETADDRINFO getaddrinfo
  917. #define CURL_FREEADDRINFO freeaddrinfo
  918. #define CURL_SOCKET socket
  919. #ifdef HAVE_SOCKETPAIR
  920. #define CURL_SOCKETPAIR socketpair
  921. #endif
  922. #define CURL_ACCEPT accept
  923. #ifdef HAVE_ACCEPT4
  924. #define CURL_ACCEPT4 accept4
  925. #endif
  926. #endif /* CURLDEBUG */
  927. /* Allocator macros */
  928. #ifdef CURLDEBUG
  929. #define curlx_strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
  930. #define curlx_malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__)
  931. #define curlx_calloc(nbelem, size) \
  932. curl_dbg_calloc(nbelem, size, __LINE__, __FILE__)
  933. #define curlx_realloc(ptr, size) \
  934. curl_dbg_realloc(ptr, size, __LINE__, __FILE__)
  935. #define curlx_free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__)
  936. #ifdef _WIN32
  937. #ifdef UNICODE
  938. #define curlx_tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
  939. #else
  940. #define curlx_tcsdup(ptr) curlx_strdup(ptr)
  941. #endif
  942. #endif /* _WIN32 */
  943. #else /* !CURLDEBUG */
  944. #ifdef BUILDING_LIBCURL
  945. #define curlx_strdup(ptr) Curl_cstrdup(ptr)
  946. #define curlx_malloc(size) Curl_cmalloc(size)
  947. #define curlx_calloc(nbelem, size) Curl_ccalloc(nbelem, size)
  948. #define curlx_realloc(ptr, size) Curl_crealloc(ptr, size)
  949. #define curlx_free(ptr) Curl_cfree(ptr)
  950. #else /* !BUILDING_LIBCURL */
  951. #ifdef _WIN32
  952. #define curlx_strdup(ptr) _strdup(ptr)
  953. #else
  954. #define curlx_strdup(ptr) strdup(ptr)
  955. #endif
  956. #define curlx_malloc(size) malloc(size)
  957. #define curlx_calloc(nbelem, size) calloc(nbelem, size)
  958. #define curlx_realloc(ptr, size) realloc(ptr, size)
  959. #define curlx_free(ptr) free(ptr)
  960. #endif /* BUILDING_LIBCURL */
  961. #ifdef _WIN32
  962. #ifdef UNICODE
  963. #define curlx_tcsdup(ptr) Curl_wcsdup(ptr)
  964. #else
  965. #define curlx_tcsdup(ptr) curlx_strdup(ptr)
  966. #endif
  967. #endif /* _WIN32 */
  968. #endif /* CURLDEBUG */
  969. /* Some versions of the Android NDK is missing the declaration */
  970. #if defined(HAVE_GETPWUID_R) && \
  971. defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
  972. struct passwd;
  973. int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf,
  974. size_t buflen, struct passwd **result);
  975. #endif
  976. #ifdef UNITTESTS
  977. #define UNITTEST
  978. #else
  979. #define UNITTEST static
  980. #endif
  981. #ifdef USE_NGHTTP2
  982. #define USE_HTTP2
  983. #endif
  984. #if (defined(USE_NGTCP2) && defined(USE_NGHTTP3)) || \
  985. (defined(USE_OPENSSL_QUIC) && defined(USE_NGHTTP3)) || \
  986. defined(USE_QUICHE)
  987. #ifdef CURL_WITH_MULTI_SSL
  988. #error "MultiSSL combined with QUIC is not supported"
  989. #endif
  990. #define USE_HTTP3
  991. #endif
  992. /* WebAssembly builds have TCP_NODELAY, but runtime support is missing. */
  993. #ifndef __EMSCRIPTEN__
  994. #define CURL_TCP_NODELAY_SUPPORTED
  995. #endif
  996. /* Certain Windows implementations are not aligned with what curl expects,
  997. so always use the local one on this platform. E.g. the mingw-w64
  998. implementation can return wrong results for non-ASCII inputs. */
  999. #if defined(HAVE_BASENAME) && defined(_WIN32)
  1000. #undef HAVE_BASENAME
  1001. #endif
  1002. #if defined(USE_UNIX_SOCKETS) && defined(_WIN32)
  1003. /* Offered by mingw-w64 v10+. MS SDK 10.17763/~VS2017+. */
  1004. #if defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR >= 10)
  1005. # include <afunix.h>
  1006. #elif !defined(UNIX_PATH_MAX) /* Replicate logic present in afunix.h */
  1007. # define UNIX_PATH_MAX 108
  1008. /* !checksrc! disable TYPEDEFSTRUCT 1 */
  1009. typedef struct sockaddr_un {
  1010. CURL_SA_FAMILY_T sun_family;
  1011. char sun_path[UNIX_PATH_MAX];
  1012. } SOCKADDR_UN, *PSOCKADDR_UN;
  1013. #endif
  1014. #endif
  1015. #ifdef USE_OPENSSL
  1016. /* OpenSSLv3 marks DES, MD5 and ENGINE functions deprecated but we have no
  1017. replacements (yet) so tell the compiler to not warn for them. */
  1018. # define OPENSSL_SUPPRESS_DEPRECATED
  1019. # ifdef _WIN32
  1020. /* Silence LibreSSL warnings about wincrypt.h collision. Works in 3.8.2+ */
  1021. # ifndef LIBRESSL_DISABLE_OVERRIDE_WINCRYPT_DEFINES_WARNING
  1022. # define LIBRESSL_DISABLE_OVERRIDE_WINCRYPT_DEFINES_WARNING
  1023. # endif
  1024. # endif
  1025. #endif
  1026. #ifdef CURL_INLINE
  1027. /* 'CURL_INLINE' defined, use as-is */
  1028. #elif defined(inline)
  1029. # define CURL_INLINE inline /* 'inline' defined, assumed correct */
  1030. #elif defined(__cplusplus)
  1031. /* The code is compiled with C++ compiler.
  1032. C++ always supports 'inline'. */
  1033. # define CURL_INLINE inline /* 'inline' keyword supported */
  1034. #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901
  1035. /* C99 (and later) supports 'inline' keyword */
  1036. # define CURL_INLINE inline /* 'inline' keyword supported */
  1037. #elif defined(__GNUC__) && __GNUC__ >= 3
  1038. /* GCC supports '__inline__' as an extension */
  1039. # define CURL_INLINE __inline__
  1040. #elif defined(_MSC_VER)
  1041. # define CURL_INLINE __inline
  1042. #else
  1043. /* Probably 'inline' is not supported by compiler.
  1044. Define to the empty string to be on the safe side. */
  1045. # define CURL_INLINE /* empty */
  1046. #endif
  1047. #endif /* HEADER_CURL_SETUP_H */