curl_setup.h 36 KB

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