curl_setup.h 37 KB

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