curl_setup.h 31 KB

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