curl_setup.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  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. /* Set default _WIN32_WINNT */
  32. #ifdef __MINGW32__
  33. #include <_mingw.h>
  34. #endif
  35. /* Workaround for Homebrew gcc 12.4.0, 13.3.0, 14.1.0, 14.2.0 (initial build)
  36. that started advertising the `availability` attribute, which then gets used
  37. by Apple SDK, but, in a way incompatible with gcc, resulting in misc errors
  38. inside SDK headers, e.g.:
  39. error: attributes should be specified before the declarator in a function
  40. definition
  41. error: expected ',' or '}' before
  42. Followed by missing declarations.
  43. Work it around by overriding the built-in feature-check macro used by the
  44. headers to enable the problematic attributes. This makes the feature check
  45. fail. Fixed in 14.2.0_1. Disable the workaround if the fix is detected. */
  46. #if defined(__APPLE__) && !defined(__clang__) && defined(__GNUC__) && \
  47. defined(__has_attribute)
  48. # if !defined(__has_feature)
  49. # define availability curl_pp_attribute_disabled
  50. # elif !__has_feature(attribute_availability)
  51. # define availability curl_pp_attribute_disabled
  52. # endif
  53. #endif
  54. #if defined(__APPLE__)
  55. #include <sys/types.h>
  56. #include <TargetConditionals.h>
  57. /* Fixup faulty target macro initialization in macOS SDK since v14.4 (as of
  58. 15.0 beta). The SDK target detection in `TargetConditionals.h` correctly
  59. detects macOS, but fails to set the macro's old name `TARGET_OS_OSX`, then
  60. continues to set it to a default value of 0. Other parts of the SDK still
  61. rely on the old name, and with this inconsistency our builds fail due to
  62. missing declarations. It happens when using mainline llvm older than v18.
  63. Later versions fixed it by predefining these target macros, avoiding the
  64. faulty dynamic detection. gcc is not affected (for now) because it lacks
  65. the necessary dynamic detection features, so the SDK falls back to
  66. a codepath that sets both the old and new macro to 1. */
  67. #if defined(TARGET_OS_MAC) && TARGET_OS_MAC && \
  68. defined(TARGET_OS_OSX) && !TARGET_OS_OSX && \
  69. (!defined(TARGET_OS_IPHONE) || !TARGET_OS_IPHONE) && \
  70. (!defined(TARGET_OS_SIMULATOR) || !TARGET_OS_SIMULATOR)
  71. #undef TARGET_OS_OSX
  72. #define TARGET_OS_OSX TARGET_OS_MAC
  73. #endif
  74. #endif
  75. #ifdef _MSC_VER
  76. /* Disable Visual Studio warnings: 4127 "conditional expression is constant" */
  77. #pragma warning(disable:4127)
  78. /* Avoid VS2005 and upper complaining about portable C functions. */
  79. #ifndef _CRT_NONSTDC_NO_DEPRECATE
  80. #define _CRT_NONSTDC_NO_DEPRECATE /* for strdup(), write(), etc. */
  81. #endif
  82. #ifndef _CRT_SECURE_NO_DEPRECATE
  83. #define _CRT_SECURE_NO_DEPRECATE /* for fopen(), getenv(), etc. */
  84. #endif
  85. #endif /* _MSC_VER */
  86. #ifdef _WIN32
  87. /*
  88. * Do not include unneeded stuff in Windows headers to avoid compiler
  89. * warnings and macro clashes.
  90. * Make sure to define this macro before including any Windows headers.
  91. */
  92. # ifndef WIN32_LEAN_AND_MEAN
  93. # define WIN32_LEAN_AND_MEAN
  94. # endif
  95. # ifndef NOGDI
  96. # define NOGDI
  97. # endif
  98. /* Detect Windows App environment which has a restricted access
  99. * to the Win32 APIs. */
  100. # if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \
  101. defined(WINAPI_FAMILY)
  102. # include <winapifamily.h>
  103. # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
  104. !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
  105. # define CURL_WINDOWS_UWP
  106. # endif
  107. # endif
  108. #endif
  109. /* Compatibility */
  110. #ifdef ENABLE_IPV6
  111. #define USE_IPV6 1
  112. #endif
  113. /*
  114. * Include configuration script results or hand-crafted
  115. * configuration file for platforms which lack config tool.
  116. */
  117. #ifdef HAVE_CONFIG_H
  118. #include "curl_config.h"
  119. #else /* HAVE_CONFIG_H */
  120. #ifdef _WIN32
  121. # include "config-win32.h"
  122. #endif
  123. #ifdef macintosh
  124. # include "config-mac.h"
  125. #endif
  126. #ifdef __riscos__
  127. # include "config-riscos.h"
  128. #endif
  129. #ifdef __OS400__
  130. # include "config-os400.h"
  131. #endif
  132. #ifdef __PLAN9__
  133. # include "config-plan9.h"
  134. #endif
  135. #endif /* HAVE_CONFIG_H */
  136. /* ================================================================ */
  137. /* Definition of preprocessor macros/symbols which modify compiler */
  138. /* behavior or generated code characteristics must be done here, */
  139. /* as appropriate, before any system header file is included. It is */
  140. /* also possible to have them defined in the config file included */
  141. /* before this point. As a result of all this we frown inclusion of */
  142. /* system header files in our config files, avoid this at any cost. */
  143. /* ================================================================ */
  144. /*
  145. * AIX 4.3 and newer needs _THREAD_SAFE defined to build
  146. * proper reentrant code. Others may also need it.
  147. */
  148. #ifdef NEED_THREAD_SAFE
  149. # ifndef _THREAD_SAFE
  150. # define _THREAD_SAFE
  151. # endif
  152. #endif
  153. /*
  154. * Tru64 needs _REENTRANT set for a few function prototypes and
  155. * things to appear in the system header files. Unixware needs it
  156. * to build proper reentrant code. Others may also need it.
  157. */
  158. #ifdef NEED_REENTRANT
  159. # ifndef _REENTRANT
  160. # define _REENTRANT
  161. # endif
  162. #endif
  163. /* Solaris needs this to get a POSIX-conformant getpwuid_r */
  164. #if defined(sun) || defined(__sun)
  165. # ifndef _POSIX_PTHREAD_SEMANTICS
  166. # define _POSIX_PTHREAD_SEMANTICS 1
  167. # endif
  168. #endif
  169. /* ================================================================ */
  170. /* If you need to include a system header file for your platform, */
  171. /* please, do it beyond the point further indicated in this file. */
  172. /* ================================================================ */
  173. /* Give calloc a chance to be dragging in early, so we do not redefine */
  174. #if defined(USE_THREADS_POSIX) && defined(HAVE_PTHREAD_H)
  175. # include <pthread.h>
  176. #endif
  177. /*
  178. * Disable other protocols when http is the only one desired.
  179. */
  180. #ifdef HTTP_ONLY
  181. # ifndef CURL_DISABLE_DICT
  182. # define CURL_DISABLE_DICT
  183. # endif
  184. # ifndef CURL_DISABLE_FILE
  185. # define CURL_DISABLE_FILE
  186. # endif
  187. # ifndef CURL_DISABLE_FTP
  188. # define CURL_DISABLE_FTP
  189. # endif
  190. # ifndef CURL_DISABLE_GOPHER
  191. # define CURL_DISABLE_GOPHER
  192. # endif
  193. # ifndef CURL_DISABLE_IMAP
  194. # define CURL_DISABLE_IMAP
  195. # endif
  196. # ifndef CURL_DISABLE_LDAP
  197. # define CURL_DISABLE_LDAP
  198. # endif
  199. # ifndef CURL_DISABLE_LDAPS
  200. # define CURL_DISABLE_LDAPS
  201. # endif
  202. # ifndef CURL_DISABLE_MQTT
  203. # define CURL_DISABLE_MQTT
  204. # endif
  205. # ifndef CURL_DISABLE_POP3
  206. # define CURL_DISABLE_POP3
  207. # endif
  208. # ifndef CURL_DISABLE_RTSP
  209. # define CURL_DISABLE_RTSP
  210. # endif
  211. # ifndef CURL_DISABLE_SMB
  212. # define CURL_DISABLE_SMB
  213. # endif
  214. # ifndef CURL_DISABLE_SMTP
  215. # define CURL_DISABLE_SMTP
  216. # endif
  217. # ifndef CURL_DISABLE_TELNET
  218. # define CURL_DISABLE_TELNET
  219. # endif
  220. # ifndef CURL_DISABLE_TFTP
  221. # define CURL_DISABLE_TFTP
  222. # endif
  223. #endif
  224. /*
  225. * When http is disabled rtsp is not supported.
  226. */
  227. #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP)
  228. # define CURL_DISABLE_RTSP
  229. #endif
  230. /*
  231. * When HTTP is disabled, disable HTTP-only features
  232. */
  233. #if defined(CURL_DISABLE_HTTP)
  234. # define CURL_DISABLE_ALTSVC 1
  235. # define CURL_DISABLE_COOKIES 1
  236. # define CURL_DISABLE_BASIC_AUTH 1
  237. # define CURL_DISABLE_BEARER_AUTH 1
  238. # define CURL_DISABLE_AWS 1
  239. # define CURL_DISABLE_DOH 1
  240. # define CURL_DISABLE_FORM_API 1
  241. # define CURL_DISABLE_HEADERS_API 1
  242. # define CURL_DISABLE_HSTS 1
  243. # define CURL_DISABLE_HTTP_AUTH 1
  244. #endif
  245. /* ================================================================ */
  246. /* No system header file shall be included in this file before this */
  247. /* point. */
  248. /* ================================================================ */
  249. /*
  250. * OS/400 setup file includes some system headers.
  251. */
  252. #ifdef __OS400__
  253. # include "setup-os400.h"
  254. #endif
  255. /*
  256. * VMS setup file includes some system headers.
  257. */
  258. #ifdef __VMS
  259. # include "setup-vms.h"
  260. #endif
  261. /*
  262. * Windows setup file includes some system headers.
  263. */
  264. #ifdef _WIN32
  265. # include "setup-win32.h"
  266. #endif
  267. #include <curl/system.h>
  268. /* Helper macro to expand and concatenate two macros.
  269. * Direct macros concatenation does not work because macros
  270. * are not expanded before direct concatenation.
  271. */
  272. #define CURL_CONC_MACROS_(A,B) A ## B
  273. #define CURL_CONC_MACROS(A,B) CURL_CONC_MACROS_(A,B)
  274. /* curl uses its own printf() function internally. It understands the GNU
  275. * format. Use this format, so that is matches the GNU format attribute we
  276. * use with the MinGW compiler, allowing it to verify them at compile-time.
  277. */
  278. #ifdef __MINGW32__
  279. # undef CURL_FORMAT_CURL_OFF_T
  280. # undef CURL_FORMAT_CURL_OFF_TU
  281. # define CURL_FORMAT_CURL_OFF_T "lld"
  282. # define CURL_FORMAT_CURL_OFF_TU "llu"
  283. #endif
  284. /* based on logic in "curl/mprintf.h" */
  285. #if (defined(__GNUC__) || defined(__clang__) || \
  286. defined(__IAR_SYSTEMS_ICC__)) && \
  287. defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
  288. !defined(CURL_NO_FMT_CHECKS)
  289. #if defined(__MINGW32__) && !defined(__clang__)
  290. #define CURL_PRINTF(fmt, arg) \
  291. __attribute__((format(gnu_printf, fmt, arg)))
  292. #else
  293. #define CURL_PRINTF(fmt, arg) \
  294. __attribute__((format(__printf__, fmt, arg)))
  295. #endif
  296. #else
  297. #define CURL_PRINTF(fmt, arg)
  298. #endif
  299. /* Override default printf mask check rules in "curl/mprintf.h" */
  300. #define CURL_TEMP_PRINTF CURL_PRINTF
  301. /* Workaround for mainline llvm v16 and earlier missing a built-in macro
  302. expected by macOS SDK v14 / Xcode v15 (2023) and newer.
  303. gcc (as of v14) is also missing it. */
  304. #if defined(__APPLE__) && \
  305. ((!defined(__apple_build_version__) && \
  306. defined(__clang__) && __clang_major__ < 17) || \
  307. (defined(__GNUC__) && __GNUC__ <= 14)) && \
  308. defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
  309. !defined(__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__)
  310. #define __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ \
  311. __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
  312. #endif
  313. /*
  314. * Use getaddrinfo to resolve the IPv4 address literal. If the current network
  315. * interface does not support IPv4, but supports IPv6, NAT64, and DNS64,
  316. * performing this task will result in a synthesized IPv6 address.
  317. */
  318. #if defined(__APPLE__) && !defined(USE_ARES)
  319. #define USE_RESOLVE_ON_IPS 1
  320. # if TARGET_OS_MAC && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && \
  321. defined(USE_IPV6)
  322. # define CURL_MACOS_CALL_COPYPROXIES 1
  323. # endif
  324. #endif
  325. #ifdef USE_ARES
  326. # ifndef CARES_NO_DEPRECATED
  327. # define CARES_NO_DEPRECATED /* for ares_getsock() */
  328. # endif
  329. # if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && defined(_WIN32)
  330. # define CARES_STATICLIB /* define it before including ares.h */
  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 macintosh
  339. # include <extra/stricmp.h>
  340. # include <extra/strdup.h>
  341. #endif
  342. #ifdef __AMIGA__
  343. # ifdef __amigaos4__
  344. # define __USE_INLINE__
  345. /* use our own resolver which uses runtime feature detection */
  346. # define CURLRES_AMIGA
  347. /* getaddrinfo() currently crashes bsdsocket.library, so disable */
  348. # undef HAVE_GETADDRINFO
  349. # if !(defined(__NEWLIB__) || \
  350. (defined(__CLIB2__) && defined(__THREAD_SAFE)))
  351. /* disable threaded resolver with clib2 - requires newlib or clib-ts */
  352. # undef USE_THREADS_POSIX
  353. # endif
  354. # endif
  355. # include <exec/types.h>
  356. # include <exec/execbase.h>
  357. # include <proto/exec.h>
  358. # include <proto/dos.h>
  359. # include <unistd.h>
  360. # if defined(HAVE_PROTO_BSDSOCKET_H) && \
  361. (!defined(__amigaos4__) || defined(USE_AMISSL))
  362. /* use bsdsocket.library directly, instead of libc networking functions */
  363. # define _SYS_MBUF_H /* m_len define clashes with curl */
  364. # include <proto/bsdsocket.h>
  365. # ifdef __amigaos4__
  366. int Curl_amiga_select(int nfds, fd_set *readfds, fd_set *writefds,
  367. fd_set *errorfds, struct timeval *timeout);
  368. # define select(a,b,c,d,e) Curl_amiga_select(a,b,c,d,e)
  369. # else
  370. # define select(a,b,c,d,e) WaitSelect(a,b,c,d,e,0)
  371. # endif
  372. /* must not use libc's fcntl() on bsdsocket.library sockfds! */
  373. # undef HAVE_FCNTL
  374. # undef HAVE_FCNTL_O_NONBLOCK
  375. # else
  376. /* use libc networking and hence close() and fnctl() */
  377. # undef HAVE_CLOSESOCKET_CAMEL
  378. # undef HAVE_IOCTLSOCKET_CAMEL
  379. # endif
  380. /*
  381. * In clib2 arpa/inet.h warns that some prototypes may clash
  382. * with bsdsocket.library. This avoids the definition of those.
  383. */
  384. # define __NO_NET_API
  385. #endif
  386. #include <stdio.h>
  387. #include <assert.h>
  388. #ifdef __TANDEM /* for ns*-tandem-nsk systems */
  389. # if ! defined __LP64
  390. # include <floss.h> /* FLOSS is only used for 32-bit builds. */
  391. # endif
  392. #endif
  393. #ifndef STDC_HEADERS /* no standard C headers! */
  394. #include <curl/stdcheaders.h>
  395. #endif
  396. #ifdef _WIN32
  397. #define Curl_getpid() GetCurrentProcessId()
  398. #else
  399. #define Curl_getpid() getpid()
  400. #endif
  401. /*
  402. * Large file (>2Gb) support using Win32 functions.
  403. */
  404. #ifdef USE_WIN32_LARGE_FILES
  405. # include <io.h>
  406. # include <sys/types.h>
  407. # include <sys/stat.h>
  408. # undef lseek
  409. # define lseek(fdes,offset,whence) _lseeki64(fdes, offset, whence)
  410. # undef fstat
  411. # define fstat(fdes,stp) _fstati64(fdes, stp)
  412. # undef stat
  413. # define stat(fname,stp) curlx_win32_stat(fname, stp)
  414. # define struct_stat struct _stati64
  415. # define LSEEK_ERROR (__int64)-1
  416. # define open curlx_win32_open
  417. # define fopen(fname,mode) curlx_win32_fopen(fname, mode)
  418. int curlx_win32_open(const char *filename, int oflag, ...);
  419. int curlx_win32_stat(const char *path, struct_stat *buffer);
  420. FILE *curlx_win32_fopen(const char *filename, const char *mode);
  421. #endif
  422. #ifdef __DJGPP__
  423. /* Requires DJGPP 2.04 */
  424. # include <unistd.h>
  425. # undef lseek
  426. # define lseek(fdes,offset,whence) llseek(fdes, offset, whence)
  427. # define LSEEK_ERROR (offset_t)-1
  428. #endif
  429. /*
  430. * Small file (<2Gb) support using Win32 functions.
  431. */
  432. #if defined(_WIN32) && !defined(USE_WIN32_LARGE_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. * Single-threaded option was last available in VS2005: _MSC_VER <= 1400
  600. */
  601. #if defined(_MSC_VER) && !defined(_MT) /* available in _MSC_VER <= 1400 */
  602. # undef USE_THREADS_POSIX
  603. # undef USE_THREADS_WIN32
  604. #endif
  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) || 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_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. #if !defined(CURL_DISABLE_NTLM)
  668. # if defined(USE_OPENSSL) || defined(USE_MBEDTLS) || \
  669. defined(USE_GNUTLS) || defined(USE_SECTRANSP) || \
  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 UNUSED_PARAM __attribute__((__unused__))
  689. # define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  690. #elif defined(__IAR_SYSTEMS_ICC__)
  691. # define UNUSED_PARAM __attribute__((__unused__))
  692. # if (__VER__ >= 9040001)
  693. # define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  694. # else
  695. # define WARN_UNUSED_RESULT
  696. # endif
  697. #else
  698. # define UNUSED_PARAM /* NOTHING */
  699. # define WARN_UNUSED_RESULT
  700. #endif
  701. /* noreturn attribute */
  702. #if !defined(CURL_NORETURN)
  703. #if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__clang__) || \
  704. defined(__IAR_SYSTEMS_ICC__)
  705. # define CURL_NORETURN __attribute__((__noreturn__))
  706. #elif defined(_MSC_VER)
  707. # define CURL_NORETURN __declspec(noreturn)
  708. #else
  709. # define CURL_NORETURN
  710. #endif
  711. #endif
  712. /* fallthrough attribute */
  713. #if !defined(FALLTHROUGH)
  714. #if (defined(__GNUC__) && __GNUC__ >= 7) || \
  715. (defined(__clang__) && __clang_major__ >= 10)
  716. # define FALLTHROUGH() __attribute__((fallthrough))
  717. #else
  718. # define FALLTHROUGH() do {} while (0)
  719. #endif
  720. #endif
  721. /*
  722. * Include macros and defines that should only be processed once.
  723. */
  724. #ifndef HEADER_CURL_SETUP_ONCE_H
  725. #include "curl_setup_once.h"
  726. #endif
  727. /*
  728. * Definition of our NOP statement Object-like macro
  729. */
  730. #ifndef Curl_nop_stmt
  731. #define Curl_nop_stmt do { } while(0)
  732. #endif
  733. /*
  734. * Ensure that Winsock and lwIP TCP/IP stacks are not mixed.
  735. */
  736. #if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)
  737. # if defined(SOCKET) || defined(USE_WINSOCK)
  738. # error "Winsock and lwIP TCP/IP stack definitions shall not coexist!"
  739. # endif
  740. #endif
  741. /*
  742. * shutdown() flags for systems that do not define them
  743. */
  744. #ifndef SHUT_RD
  745. #define SHUT_RD 0x00
  746. #endif
  747. #ifndef SHUT_WR
  748. #define SHUT_WR 0x01
  749. #endif
  750. #ifndef SHUT_RDWR
  751. #define SHUT_RDWR 0x02
  752. #endif
  753. /* Define S_ISREG if not defined by system headers, e.g. MSVC */
  754. #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
  755. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  756. #endif
  757. /* Define S_ISDIR if not defined by system headers, e.g. MSVC */
  758. #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
  759. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  760. #endif
  761. /* Since O_BINARY is used in bitmasks, setting it to zero makes it usable in
  762. source code but yet it does not ruin anything */
  763. #ifdef O_BINARY
  764. #define CURL_O_BINARY O_BINARY
  765. #else
  766. #define CURL_O_BINARY 0
  767. #endif
  768. /* In Windows the default file mode is text but an application can override it.
  769. Therefore we specify it explicitly. https://github.com/curl/curl/pull/258
  770. */
  771. #if defined(_WIN32) || defined(MSDOS)
  772. #define FOPEN_READTEXT "rt"
  773. #define FOPEN_WRITETEXT "wt"
  774. #define FOPEN_APPENDTEXT "at"
  775. #elif defined(__CYGWIN__)
  776. /* Cygwin has specific behavior we need to address when _WIN32 is not defined.
  777. https://cygwin.com/cygwin-ug-net/using-textbinary.html
  778. For write we want our output to have line endings of LF and be compatible with
  779. other Cygwin utilities. For read we want to handle input that may have line
  780. endings either CRLF or LF so 't' is appropriate.
  781. */
  782. #define FOPEN_READTEXT "rt"
  783. #define FOPEN_WRITETEXT "w"
  784. #define FOPEN_APPENDTEXT "a"
  785. #else
  786. #define FOPEN_READTEXT "r"
  787. #define FOPEN_WRITETEXT "w"
  788. #define FOPEN_APPENDTEXT "a"
  789. #endif
  790. /* for systems that do not detect this in configure */
  791. #ifndef CURL_SA_FAMILY_T
  792. # if defined(HAVE_SA_FAMILY_T)
  793. # define CURL_SA_FAMILY_T sa_family_t
  794. # elif defined(HAVE_ADDRESS_FAMILY)
  795. # define CURL_SA_FAMILY_T ADDRESS_FAMILY
  796. # elif defined(__AMIGA__)
  797. # define CURL_SA_FAMILY_T unsigned char
  798. # else
  799. /* use a sensible default */
  800. # define CURL_SA_FAMILY_T unsigned short
  801. # endif
  802. #endif
  803. /* Some convenience macros to get the larger/smaller value out of two given.
  804. We prefix with CURL to prevent name collisions. */
  805. #define CURLMAX(x,y) ((x)>(y)?(x):(y))
  806. #define CURLMIN(x,y) ((x)<(y)?(x):(y))
  807. /* A convenience macro to provide both the string literal and the length of
  808. the string literal in one go, useful for functions that take "string,len"
  809. as their argument */
  810. #define STRCONST(x) x,sizeof(x)-1
  811. /* Some versions of the Android NDK is missing the declaration */
  812. #if defined(HAVE_GETPWUID_R) && \
  813. defined(__ANDROID_API__) && (__ANDROID_API__ < 21)
  814. struct passwd;
  815. int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf,
  816. size_t buflen, struct passwd **result);
  817. #endif
  818. #ifdef UNITTESTS
  819. #define UNITTEST
  820. #else
  821. #define UNITTEST static
  822. #endif
  823. #ifdef USE_NGHTTP2
  824. #define USE_HTTP2
  825. #endif
  826. #if (defined(USE_NGTCP2) && defined(USE_NGHTTP3)) || \
  827. (defined(USE_OPENSSL_QUIC) && defined(USE_NGHTTP3)) || \
  828. defined(USE_QUICHE) || defined(USE_MSH3)
  829. #ifdef CURL_WITH_MULTI_SSL
  830. #error "MultiSSL combined with QUIC is not supported"
  831. #endif
  832. #define USE_HTTP3
  833. #endif
  834. /* Certain Windows implementations are not aligned with what curl expects,
  835. so always use the local one on this platform. E.g. the mingw-w64
  836. implementation can return wrong results for non-ASCII inputs. */
  837. #if defined(HAVE_BASENAME) && defined(_WIN32)
  838. #undef HAVE_BASENAME
  839. #endif
  840. #if defined(USE_UNIX_SOCKETS) && defined(_WIN32)
  841. # if !defined(UNIX_PATH_MAX)
  842. /* Replicating logic present in afunix.h
  843. (distributed with newer Windows 10 SDK versions only) */
  844. # define UNIX_PATH_MAX 108
  845. /* !checksrc! disable TYPEDEFSTRUCT 1 */
  846. typedef struct sockaddr_un {
  847. CURL_SA_FAMILY_T sun_family;
  848. char sun_path[UNIX_PATH_MAX];
  849. } SOCKADDR_UN, *PSOCKADDR_UN;
  850. # define WIN32_SOCKADDR_UN
  851. # endif
  852. #endif
  853. /* OpenSSLv3 marks DES, MD5 and ENGINE functions deprecated but we have no
  854. replacements (yet) so tell the compiler to not warn for them. */
  855. #ifdef USE_OPENSSL
  856. #define OPENSSL_SUPPRESS_DEPRECATED
  857. #endif
  858. #if defined(CURL_INLINE)
  859. /* 'CURL_INLINE' defined, use as-is */
  860. #elif defined(inline)
  861. # define CURL_INLINE inline /* 'inline' defined, assumed correct */
  862. #elif defined(__cplusplus)
  863. /* The code is compiled with C++ compiler.
  864. C++ always supports 'inline'. */
  865. # define CURL_INLINE inline /* 'inline' keyword supported */
  866. #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901
  867. /* C99 (and later) supports 'inline' keyword */
  868. # define CURL_INLINE inline /* 'inline' keyword supported */
  869. #elif defined(__GNUC__) && __GNUC__ >= 3
  870. /* GCC supports '__inline__' as an extension */
  871. # define CURL_INLINE __inline__
  872. #elif defined(_MSC_VER)
  873. # define CURL_INLINE __inline
  874. #else
  875. /* Probably 'inline' is not supported by compiler.
  876. Define to the empty string to be on the safe side. */
  877. # define CURL_INLINE /* empty */
  878. #endif
  879. #endif /* HEADER_CURL_SETUP_H */