curl_setup.h 28 KB

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