/src/curl/lib/curl_setup.h
Line | Count | Source |
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, <daniel@haxx.se>, 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 | | |
27 | | #if defined(BUILDING_LIBCURL) && !defined(CURL_NO_OLDIES) |
28 | | #define CURL_NO_OLDIES |
29 | | #endif |
30 | | |
31 | | /* Set default _WIN32_WINNT */ |
32 | | #ifdef __MINGW32__ |
33 | | #include <_mingw.h> |
34 | | #endif |
35 | | |
36 | | /* Workaround for Homebrew gcc 12.4.0, 13.3.0, 14.1.0, 14.2.0 (initial build) |
37 | | that started advertising the `availability` attribute, which then gets used |
38 | | by Apple SDK, but, in a way incompatible with gcc, resulting in misc errors |
39 | | inside SDK headers, e.g.: |
40 | | error: attributes should be specified before the declarator in a function |
41 | | definition |
42 | | error: expected ',' or '}' before |
43 | | Followed by missing declarations. |
44 | | Work it around by overriding the built-in feature-check macro used by the |
45 | | headers to enable the problematic attributes. This makes the feature check |
46 | | fail. Fixed in 14.2.0_1. Disable the workaround if the fix is detected. */ |
47 | | #if defined(__APPLE__) && !defined(__clang__) && defined(__GNUC__) && \ |
48 | | defined(__has_attribute) |
49 | | # if !defined(__has_feature) /* Keep this PP check separate from others */ |
50 | | # define availability curl_pp_attribute_disabled |
51 | | # elif !__has_feature(attribute_availability) |
52 | | # define availability curl_pp_attribute_disabled |
53 | | # endif |
54 | | #endif |
55 | | |
56 | | #ifdef __APPLE__ |
57 | | #include <sys/types.h> |
58 | | #include <TargetConditionals.h> |
59 | | /* Fixup faulty target macro initialization in macOS SDK since v14.4 (as of |
60 | | 15.0 beta). The SDK target detection in `TargetConditionals.h` correctly |
61 | | detects macOS, but fails to set the macro's old name `TARGET_OS_OSX`, then |
62 | | continues to set it to a default value of 0. Other parts of the SDK still |
63 | | rely on the old name, and with this inconsistency our builds fail due to |
64 | | missing declarations. It happens when using mainline llvm older than v18. |
65 | | Later versions fixed it by predefining these target macros, avoiding the |
66 | | faulty dynamic detection. gcc is not affected (for now) because it lacks |
67 | | the necessary dynamic detection features, so the SDK falls back to |
68 | | a codepath that sets both the old and new macro to 1. */ |
69 | | #if defined(TARGET_OS_MAC) && TARGET_OS_MAC && \ |
70 | | defined(TARGET_OS_OSX) && !TARGET_OS_OSX && \ |
71 | | (!defined(TARGET_OS_IPHONE) || !TARGET_OS_IPHONE) && \ |
72 | | (!defined(TARGET_OS_SIMULATOR) || !TARGET_OS_SIMULATOR) |
73 | | #undef TARGET_OS_OSX |
74 | | #define TARGET_OS_OSX TARGET_OS_MAC |
75 | | #endif |
76 | | #endif |
77 | | |
78 | | #if defined(__MINGW32__) && \ |
79 | | (!defined(__MINGW64_VERSION_MAJOR) || (__MINGW64_VERSION_MAJOR < 3)) |
80 | | #error "Building curl requires mingw-w64 3.0 or later" |
81 | | #endif |
82 | | |
83 | | /* Visual Studio 2010 is the minimum Visual Studio version we support. |
84 | | Workarounds for older versions of Visual Studio have been removed. */ |
85 | | #if defined(_MSC_VER) && (_MSC_VER < 1600) |
86 | | #error "Ancient versions of Visual Studio are no longer supported due to bugs." |
87 | | #endif |
88 | | |
89 | | #ifdef _MSC_VER |
90 | | /* Disable Visual Studio warnings: 4127 "conditional expression is constant" */ |
91 | | #pragma warning(disable:4127) |
92 | | #ifndef _CRT_SECURE_NO_WARNINGS |
93 | | #define _CRT_SECURE_NO_WARNINGS /* for getenv(), sscanf() */ |
94 | | #endif |
95 | | #endif /* _MSC_VER */ |
96 | | |
97 | | #ifdef _WIN32 |
98 | | /* |
99 | | * Do not include unneeded stuff in Windows headers to avoid compiler |
100 | | * warnings and macro clashes. |
101 | | * Make sure to define this macro before including any Windows headers. |
102 | | */ |
103 | | # ifndef WIN32_LEAN_AND_MEAN |
104 | | # define WIN32_LEAN_AND_MEAN |
105 | | # endif |
106 | | # ifndef NOGDI |
107 | | # define NOGDI |
108 | | # endif |
109 | | |
110 | | /* Detect Windows App environment which has a restricted access |
111 | | * to the Win32 APIs. */ |
112 | | # if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \ |
113 | | defined(WINAPI_FAMILY) |
114 | | # include <winapifamily.h> |
115 | | # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ |
116 | | !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) |
117 | | # define CURL_WINDOWS_UWP |
118 | | # endif |
119 | | # endif |
120 | | |
121 | | /* Mandatory to define SECURITY_WIN32 or SECURITY_KERNEL to indicating who is |
122 | | compiling the code. */ |
123 | | #undef SECURITY_KERNEL |
124 | | #undef SECURITY_WIN32 |
125 | | #define SECURITY_WIN32 /* for <sspi.h> */ |
126 | | #endif |
127 | | |
128 | | /* Compatibility */ |
129 | | #ifdef ENABLE_IPV6 |
130 | | #define USE_IPV6 1 |
131 | | #endif |
132 | | |
133 | | /* |
134 | | * Include configuration script results or hand-crafted |
135 | | * configuration file for platforms which lack config tool. |
136 | | */ |
137 | | |
138 | | #ifdef HAVE_CONFIG_H |
139 | | |
140 | | #include "curl_config.h" |
141 | | |
142 | | #else /* HAVE_CONFIG_H */ |
143 | | |
144 | | #ifdef _WIN32 |
145 | | # include "config-win32.h" |
146 | | #endif |
147 | | |
148 | | #ifdef macintosh |
149 | | # include "config-mac.h" |
150 | | #endif |
151 | | |
152 | | #ifdef __riscos__ |
153 | | # include "config-riscos.h" |
154 | | #endif |
155 | | |
156 | | #ifdef __OS400__ |
157 | | # include "config-os400.h" |
158 | | #endif |
159 | | |
160 | | #endif /* HAVE_CONFIG_H */ |
161 | | |
162 | | #ifdef _WIN32 |
163 | | # if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600) |
164 | | # error The minimum build target is Windows Vista (0x0600) |
165 | | # endif |
166 | | |
167 | | # if !defined(CURL_WINDOWS_UWP) && (defined(_MSC_VER) || defined(__MINGW32__)) |
168 | | # ifndef HAVE_IF_NAMETOINDEX |
169 | | # define HAVE_IF_NAMETOINDEX |
170 | | # endif |
171 | | # endif |
172 | | #endif |
173 | | |
174 | | /* ================================================================ */ |
175 | | /* Definition of preprocessor macros/symbols which modify compiler */ |
176 | | /* behavior or generated code characteristics must be done here, */ |
177 | | /* as appropriate, before any system header file is included. It is */ |
178 | | /* also possible to have them defined in the config file included */ |
179 | | /* before this point. As a result of all this we frown inclusion of */ |
180 | | /* system header files in our config files, avoid this at any cost. */ |
181 | | /* ================================================================ */ |
182 | | |
183 | | #ifdef HAVE_LIBZ |
184 | | # ifndef ZLIB_CONST |
185 | | # define ZLIB_CONST /* Use z_const. Supported by v1.2.5.2 and upper. */ |
186 | | # endif |
187 | | #endif |
188 | | |
189 | | /* |
190 | | * AIX 4.3 and newer needs _THREAD_SAFE defined to build |
191 | | * proper reentrant code. Others may also need it. |
192 | | */ |
193 | | #ifdef NEED_THREAD_SAFE |
194 | | # ifndef _THREAD_SAFE |
195 | | # define _THREAD_SAFE |
196 | | # endif |
197 | | #endif |
198 | | |
199 | | /* |
200 | | * Tru64 needs _REENTRANT set for a few function prototypes and |
201 | | * things to appear in the system header files. Unixware needs it |
202 | | * to build proper reentrant code. Others may also need it. |
203 | | */ |
204 | | #ifdef NEED_REENTRANT |
205 | | # ifndef _REENTRANT |
206 | | # define _REENTRANT |
207 | | # endif |
208 | | #endif |
209 | | |
210 | | /* Solaris needs this to get a POSIX-conformant getpwuid_r */ |
211 | | #if defined(sun) || defined(__sun) |
212 | | # ifndef _POSIX_PTHREAD_SEMANTICS |
213 | | # define _POSIX_PTHREAD_SEMANTICS 1 |
214 | | # endif |
215 | | #endif |
216 | | |
217 | | /* ================================================================ */ |
218 | | /* If you need to include a system header file for your platform, */ |
219 | | /* please, do it beyond the point further indicated in this file. */ |
220 | | /* ================================================================ */ |
221 | | |
222 | | /* Give calloc a chance to be dragging in early, so we do not redefine */ |
223 | | #ifdef HAVE_THREADS_POSIX |
224 | | # include <pthread.h> |
225 | | #endif |
226 | | |
227 | | /* |
228 | | * Disable other protocols when http is the only one desired. |
229 | | */ |
230 | | #ifdef HTTP_ONLY |
231 | | # ifndef CURL_DISABLE_DICT |
232 | | # define CURL_DISABLE_DICT |
233 | | # endif |
234 | | # ifndef CURL_DISABLE_FILE |
235 | | # define CURL_DISABLE_FILE |
236 | | # endif |
237 | | # ifndef CURL_DISABLE_FTP |
238 | | # define CURL_DISABLE_FTP |
239 | | # endif |
240 | | # ifndef CURL_DISABLE_GOPHER |
241 | | # define CURL_DISABLE_GOPHER |
242 | | # endif |
243 | | # ifndef CURL_DISABLE_IMAP |
244 | | # define CURL_DISABLE_IMAP |
245 | | # endif |
246 | | # ifndef CURL_DISABLE_LDAP |
247 | | # define CURL_DISABLE_LDAP |
248 | | # endif |
249 | | # ifndef CURL_DISABLE_LDAPS |
250 | | # define CURL_DISABLE_LDAPS |
251 | | # endif |
252 | | # ifndef CURL_DISABLE_MQTT |
253 | | # define CURL_DISABLE_MQTT |
254 | | # endif |
255 | | # ifndef CURL_DISABLE_POP3 |
256 | | # define CURL_DISABLE_POP3 |
257 | | # endif |
258 | | # ifndef CURL_DISABLE_RTSP |
259 | | # define CURL_DISABLE_RTSP |
260 | | # endif |
261 | | # ifndef CURL_DISABLE_SMTP |
262 | | # define CURL_DISABLE_SMTP |
263 | | # endif |
264 | | # ifndef CURL_DISABLE_TELNET |
265 | | # define CURL_DISABLE_TELNET |
266 | | # endif |
267 | | # ifndef CURL_DISABLE_TFTP |
268 | | # define CURL_DISABLE_TFTP |
269 | | # endif |
270 | | # ifndef CURL_DISABLE_WEBSOCKETS |
271 | | # define CURL_DISABLE_WEBSOCKETS |
272 | | # endif |
273 | | #endif |
274 | | |
275 | | /* |
276 | | * When http is disabled rtsp is not supported. |
277 | | */ |
278 | | #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP) |
279 | | # define CURL_DISABLE_RTSP |
280 | | #endif |
281 | | |
282 | | /* |
283 | | * When HTTP is disabled, disable HTTP-only features |
284 | | */ |
285 | | #ifdef CURL_DISABLE_HTTP |
286 | | # ifndef CURL_DISABLE_ALTSVC |
287 | | # define CURL_DISABLE_ALTSVC |
288 | | # endif |
289 | | # ifndef CURL_DISABLE_COOKIES |
290 | | # define CURL_DISABLE_COOKIES |
291 | | # endif |
292 | | # ifndef CURL_DISABLE_BASIC_AUTH |
293 | | # define CURL_DISABLE_BASIC_AUTH |
294 | | # endif |
295 | | # ifndef CURL_DISABLE_BEARER_AUTH |
296 | | # define CURL_DISABLE_BEARER_AUTH |
297 | | # endif |
298 | | # ifndef CURL_DISABLE_AWS |
299 | | # define CURL_DISABLE_AWS |
300 | | # endif |
301 | | # ifndef CURL_DISABLE_DOH |
302 | | # define CURL_DISABLE_DOH |
303 | | # endif |
304 | | # ifndef CURL_DISABLE_FORM_API |
305 | | # define CURL_DISABLE_FORM_API |
306 | | # endif |
307 | | # ifndef CURL_DISABLE_HEADERS_API |
308 | | # define CURL_DISABLE_HEADERS_API |
309 | | # endif |
310 | | # ifndef CURL_DISABLE_HSTS |
311 | | # define CURL_DISABLE_HSTS |
312 | | # endif |
313 | | # ifndef CURL_DISABLE_HTTP_AUTH |
314 | | # define CURL_DISABLE_HTTP_AUTH |
315 | | # endif |
316 | | # ifndef CURL_DISABLE_WEBSOCKETS |
317 | | # define CURL_DISABLE_WEBSOCKETS /* no WebSockets without HTTP present */ |
318 | | # endif |
319 | | #endif |
320 | | |
321 | | /* ================================================================ */ |
322 | | /* No system header file shall be included in this file before this */ |
323 | | /* point. */ |
324 | | /* ================================================================ */ |
325 | | |
326 | | /* |
327 | | * OS/400 setup file includes some system headers. |
328 | | */ |
329 | | #ifdef __OS400__ |
330 | | # include "setup-os400.h" |
331 | | #endif |
332 | | |
333 | | /* |
334 | | * VMS setup file includes some system headers. |
335 | | */ |
336 | | #ifdef __VMS |
337 | | # include "setup-vms.h" |
338 | | #endif |
339 | | |
340 | | /* |
341 | | * Windows setup file includes some system headers. |
342 | | */ |
343 | | #ifdef _WIN32 |
344 | | # include "setup-win32.h" |
345 | | #endif |
346 | | |
347 | | #include <curl/system.h> |
348 | | |
349 | | /* Helper macro to expand and concatenate two macros. |
350 | | * Direct macros concatenation does not work because macros |
351 | | * are not expanded before direct concatenation. |
352 | | */ |
353 | | #define CURL_CONC_MACROS_(A, B) A ## B |
354 | | #define CURL_CONC_MACROS(A, B) CURL_CONC_MACROS_(A, B) |
355 | | |
356 | | /* curl uses its own printf() function internally. It understands the GNU |
357 | | * format. Use this format, so that it matches the GNU format attribute we |
358 | | * use with the MinGW compiler, allowing it to verify them at compile-time. |
359 | | */ |
360 | | #ifdef __MINGW32__ |
361 | | # undef CURL_FORMAT_CURL_OFF_T |
362 | | # undef CURL_FORMAT_CURL_OFF_TU |
363 | | # define CURL_FORMAT_CURL_OFF_T "lld" |
364 | | # define CURL_FORMAT_CURL_OFF_TU "llu" |
365 | | #endif |
366 | | |
367 | | /* based on logic in "curl/mprintf.h" */ |
368 | | #if (defined(__GNUC__) || defined(__clang__) || \ |
369 | | defined(__IAR_SYSTEMS_ICC__)) && \ |
370 | | defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ |
371 | | !defined(CURL_NO_FMT_CHECKS) |
372 | | #if defined(__MINGW32__) && !defined(__clang__) |
373 | | #define CURL_PRINTF(fmt, arg) __attribute__((format(gnu_printf, fmt, arg))) |
374 | | #else |
375 | | #define CURL_PRINTF(fmt, arg) __attribute__((format(__printf__, fmt, arg))) |
376 | | #endif |
377 | | #else |
378 | | #define CURL_PRINTF(fmt, arg) |
379 | | #endif |
380 | | |
381 | | /* Override default printf mask check rules in "curl/mprintf.h" */ |
382 | | #define CURL_TEMP_PRINTF CURL_PRINTF |
383 | | |
384 | | /* Workaround for mainline llvm v16 and earlier missing a built-in macro |
385 | | expected by macOS SDK v14 / Xcode v15 (2023) and newer. |
386 | | gcc (as of v14) is also missing it. */ |
387 | | #if defined(__APPLE__) && \ |
388 | | ((!defined(__apple_build_version__) && \ |
389 | | defined(__clang__) && __clang_major__ < 17) || \ |
390 | | (defined(__GNUC__) && __GNUC__ <= 14)) && \ |
391 | | defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ |
392 | | !defined(__ENVIRONMENT_OS_VERSION_MIN_REQUIRED__) |
393 | | #define __ENVIRONMENT_OS_VERSION_MIN_REQUIRED__ \ |
394 | | __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ |
395 | | #endif |
396 | | |
397 | | /* |
398 | | * Use getaddrinfo to resolve the IPv4 address literal. If the current network |
399 | | * interface does not support IPv4, but supports IPv6, NAT64, and DNS64, |
400 | | * performing this task will result in a synthesized IPv6 address. |
401 | | */ |
402 | | #if defined(__APPLE__) && !defined(USE_ARES) |
403 | | # define USE_RESOLVE_ON_IPS 1 |
404 | | # if TARGET_OS_MAC && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) && \ |
405 | | defined(USE_IPV6) |
406 | | # define CURL_MACOS_CALL_COPYPROXIES 1 |
407 | | # endif |
408 | | #endif |
409 | | |
410 | | #ifdef USE_ARES |
411 | | # ifndef CARES_NO_DEPRECATED |
412 | | # define CARES_NO_DEPRECATED /* for ares_getsock() */ |
413 | | # endif |
414 | | # if defined(CURL_STATICLIB) && !defined(CARES_STATICLIB) && defined(_WIN32) |
415 | | # define CARES_STATICLIB /* define it before including ares.h */ |
416 | | # endif |
417 | | #endif |
418 | | |
419 | | #ifdef USE_LWIPSOCK |
420 | | # include <lwip/init.h> |
421 | | # include <lwip/sockets.h> |
422 | | # include <lwip/netdb.h> |
423 | | #endif |
424 | | |
425 | | #ifdef macintosh |
426 | | # include <extra/stricmp.h> |
427 | | # include <extra/strdup.h> |
428 | | #endif |
429 | | |
430 | | #ifdef __AMIGA__ |
431 | | # ifdef __amigaos4__ |
432 | | # define __USE_INLINE__ |
433 | | /* use our own resolver which uses runtime feature detection */ |
434 | | # define CURLRES_AMIGA |
435 | | /* getaddrinfo() currently crashes bsdsocket.library, so disable */ |
436 | | # undef HAVE_GETADDRINFO |
437 | | # if !(defined(__NEWLIB__) || \ |
438 | | (defined(__CLIB2__) && defined(__THREAD_SAFE))) |
439 | | /* disable threaded resolver with clib2 - requires newlib or clib-ts */ |
440 | | # undef USE_RESOLV_THREADED |
441 | | # endif |
442 | | # endif |
443 | | # include <exec/types.h> |
444 | | # include <exec/execbase.h> |
445 | | # include <proto/exec.h> |
446 | | # include <proto/dos.h> |
447 | | # include <unistd.h> |
448 | | # if defined(HAVE_PROTO_BSDSOCKET_H) && \ |
449 | | (!defined(__amigaos4__) || defined(USE_AMISSL)) |
450 | | /* use bsdsocket.library directly, instead of libc networking functions */ |
451 | | # define _SYS_MBUF_H /* m_len define clashes with curl */ |
452 | | # include <proto/bsdsocket.h> |
453 | | # ifdef __amigaos4__ |
454 | | int Curl_amiga_select(int nfds, fd_set *readfds, fd_set *writefds, |
455 | | fd_set *errorfds, struct timeval *timeout); |
456 | | # define select(a, b, c, d, e) Curl_amiga_select(a, b, c, d, e) |
457 | | # else |
458 | | # define select(a, b, c, d, e) WaitSelect(a, b, c, d, e, 0) |
459 | | # endif |
460 | | /* must not use libc's fcntl() on bsdsocket.library sockfds! */ |
461 | | # undef HAVE_FCNTL |
462 | | # undef HAVE_FCNTL_O_NONBLOCK |
463 | | # else |
464 | | /* use libc networking and hence close() and fnctl() */ |
465 | | # undef HAVE_CLOSESOCKET_CAMEL |
466 | | # undef HAVE_IOCTLSOCKET_CAMEL |
467 | | # endif |
468 | | /* |
469 | | * In clib2 arpa/inet.h warns that some prototypes may clash |
470 | | * with bsdsocket.library. This avoids the definition of those. |
471 | | */ |
472 | | # define __NO_NET_API |
473 | | #endif |
474 | | |
475 | | /* Whether to use eventfd() */ |
476 | | #if defined(HAVE_EVENTFD) && defined(HAVE_SYS_EVENTFD_H) |
477 | | #define USE_EVENTFD |
478 | | #endif |
479 | | |
480 | | #ifdef SO_NOSIGPIPE |
481 | | #define USE_SO_NOSIGPIPE |
482 | | #endif |
483 | | |
484 | | #include <stdio.h> |
485 | | #include <assert.h> |
486 | | |
487 | | #ifdef __TANDEM /* for ns*-tandem-nsk systems */ |
488 | | # ifndef __LP64 |
489 | | # include <floss.h> /* FLOSS is only used for 32-bit builds. */ |
490 | | # endif |
491 | | #endif |
492 | | |
493 | | #ifndef STDC_HEADERS /* no standard C headers! */ |
494 | | #include <curl/stdcheaders.h> |
495 | | #endif |
496 | | |
497 | | #include <stdint.h> |
498 | | #define HAVE_UINTPTR_T /* assume uintptr_t is provided by stdint.h */ |
499 | | |
500 | | #ifdef __DJGPP__ |
501 | | /* By default, DJGPP provides this type as a version of 'unsigned long' which |
502 | | forces us to use a define use it in printf() format strings without |
503 | | warnings. long and int are both 32 bits for this platform. */ |
504 | | #define uint32_t unsigned int |
505 | | #endif |
506 | | |
507 | | /* Disable uintptr_t for targets known to miss it from stdint.h */ |
508 | | #ifdef __OS400__ |
509 | | #undef HAVE_UINTPTR_T |
510 | | #endif |
511 | | |
512 | | #include <limits.h> |
513 | | |
514 | | #ifdef _WIN32 |
515 | | # ifdef HAVE_IO_H |
516 | | # include <io.h> |
517 | | # endif |
518 | | # include <sys/types.h> |
519 | | # include <sys/stat.h> |
520 | | /* Large file (>2Gb) support using Win32 functions. */ |
521 | | # define curl_lseek _lseeki64 |
522 | | # define LSEEK_ERROR ((__int64)-1) |
523 | | #elif defined(__DJGPP__) |
524 | | /* Requires DJGPP 2.04 */ |
525 | | # include <unistd.h> |
526 | | # define curl_lseek llseek |
527 | | # define LSEEK_ERROR ((offset_t)-1) |
528 | | #elif defined(__AMIGA__) |
529 | | # define curl_lseek(fd, offset, whence) lseek(fd, (off_t)(offset), whence) |
530 | | # define LSEEK_ERROR ((off_t)-1) |
531 | | #else |
532 | 0 | # define curl_lseek lseek |
533 | | # define LSEEK_ERROR ((off_t)-1) |
534 | | #endif |
535 | | |
536 | | #ifndef SIZEOF_TIME_T |
537 | | /* assume default size of time_t to be 32 bits */ |
538 | | #define SIZEOF_TIME_T 4 |
539 | | #endif |
540 | | |
541 | | #ifndef SIZEOF_CURL_SOCKET_T |
542 | | /* configure and cmake check and set the define */ |
543 | | # if defined(USE_WINSOCK) && defined(_WIN64) |
544 | | # define SIZEOF_CURL_SOCKET_T 8 |
545 | | # else |
546 | | /* default guess */ |
547 | | # define SIZEOF_CURL_SOCKET_T 4 |
548 | | # endif |
549 | | #endif |
550 | | |
551 | | #if SIZEOF_CURL_SOCKET_T < 8 |
552 | | #ifdef USE_WINSOCK |
553 | | # define FMT_SOCKET_T "u" |
554 | | #else |
555 | | # define FMT_SOCKET_T "d" |
556 | | #endif |
557 | | #elif defined(USE_WINSOCK) |
558 | | # define FMT_SOCKET_T "zu" |
559 | | #else |
560 | | # define FMT_SOCKET_T "qd" |
561 | | #endif |
562 | | |
563 | | /* |
564 | | * Default sizeof(off_t) in case it has not been defined in config file. |
565 | | */ |
566 | | |
567 | | #ifndef SIZEOF_OFF_T |
568 | | # if defined(__VMS) && !defined(__VAX) |
569 | | # ifdef _LARGEFILE |
570 | | # define SIZEOF_OFF_T 8 |
571 | | # endif |
572 | | # elif defined(__OS400__) && defined(__ILEC400__) |
573 | | # ifdef _LARGE_FILES |
574 | | # define SIZEOF_OFF_T 8 |
575 | | # endif |
576 | | # elif defined(__MVS__) && defined(__IBMC__) |
577 | | # if defined(_LP64) || defined(_LARGE_FILES) |
578 | | # define SIZEOF_OFF_T 8 |
579 | | # endif |
580 | | # elif defined(__370__) && defined(__IBMC__) |
581 | | # if defined(_LP64) || defined(_LARGE_FILES) |
582 | | # define SIZEOF_OFF_T 8 |
583 | | # endif |
584 | | # endif |
585 | | # ifndef SIZEOF_OFF_T |
586 | | # define SIZEOF_OFF_T 4 |
587 | | # endif |
588 | | #endif |
589 | | |
590 | | #if (SIZEOF_CURL_OFF_T < 8) |
591 | | #error "too small curl_off_t" |
592 | | #else |
593 | | /* assume SIZEOF_CURL_OFF_T == 8 */ |
594 | 0 | # define CURL_OFF_T_MAX 0x7FFFFFFFFFFFFFFF |
595 | | #endif |
596 | 0 | #define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - 1) |
597 | | |
598 | 0 | #define FMT_OFF_T CURL_FORMAT_CURL_OFF_T |
599 | | #define FMT_OFF_TU CURL_FORMAT_CURL_OFF_TU |
600 | | |
601 | | #if (SIZEOF_TIME_T == 4) |
602 | | # ifdef HAVE_TIME_T_UNSIGNED |
603 | | # define TIME_T_MAX UINT_MAX |
604 | | # define TIME_T_MIN 0 |
605 | | # else |
606 | | # define TIME_T_MAX INT_MAX |
607 | | # define TIME_T_MIN INT_MIN |
608 | | # endif |
609 | | #else |
610 | | # ifdef HAVE_TIME_T_UNSIGNED |
611 | | # define TIME_T_MAX 0xFFFFFFFFFFFFFFFF |
612 | | # define TIME_T_MIN 0 |
613 | | # else |
614 | 0 | # define TIME_T_MAX 0x7FFFFFFFFFFFFFFF |
615 | | # define TIME_T_MIN (-TIME_T_MAX - 1) |
616 | | # endif |
617 | | #endif |
618 | | |
619 | | #ifndef SIZE_MAX |
620 | | /* some limits.h headers have this defined, some do not */ |
621 | | #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4) |
622 | | #define SIZE_MAX 18446744073709551615U |
623 | | #else |
624 | | #define SIZE_MAX 4294967295U |
625 | | #endif |
626 | | #endif |
627 | | |
628 | | #ifndef SSIZE_MAX |
629 | | /* some limits.h headers have this defined, some do not */ |
630 | | #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4) |
631 | | #define SSIZE_MAX 9223372036854775807 |
632 | | #else |
633 | | #define SSIZE_MAX 2147483647 |
634 | | #endif |
635 | | #endif |
636 | | |
637 | | #if SIZEOF_LONG > SIZEOF_SIZE_T |
638 | | #error "unexpected: 'long' is larger than 'size_t'" |
639 | | #endif |
640 | | |
641 | | /* |
642 | | * Arg 2 type for gethostname in case it has not been defined in config file. |
643 | | */ |
644 | | #ifndef GETHOSTNAME_TYPE_ARG2 |
645 | | # ifdef USE_WINSOCK |
646 | | # define GETHOSTNAME_TYPE_ARG2 int |
647 | | # else |
648 | | # define GETHOSTNAME_TYPE_ARG2 size_t |
649 | | # endif |
650 | | #endif |
651 | | |
652 | | /* Below we define some functions. They should |
653 | | 4. set the SIGALRM signal timeout |
654 | | 5. set dir/file naming defines |
655 | | */ |
656 | | |
657 | | #ifdef _WIN32 |
658 | | |
659 | | # define DIR_CHAR "\\" |
660 | | |
661 | | #else /* _WIN32 */ |
662 | | |
663 | | # ifdef MSDOS /* Watt-32 */ |
664 | | |
665 | | # include <sys/ioctl.h> |
666 | | # define select(n, r, w, x, t) select_s(n, r, w, x, t) |
667 | | # define ioctl(x, y, z) ioctlsocket(x, y, (char *)(z)) |
668 | | # include <tcp.h> |
669 | | # undef word |
670 | | # undef byte |
671 | | |
672 | | # endif /* MSDOS */ |
673 | | |
674 | | # ifdef __minix |
675 | | /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */ |
676 | | extern struct tm *gmtime_r(const time_t * const timep, struct tm *tmp); |
677 | | # endif |
678 | | |
679 | 0 | # define DIR_CHAR "/" |
680 | | |
681 | | #endif /* _WIN32 */ |
682 | | |
683 | | /* We want to use mutex when available. */ |
684 | | #if defined(HAVE_THREADS_POSIX) || defined(_WIN32) |
685 | | #define USE_MUTEX |
686 | | #endif |
687 | | |
688 | | /* threaded resolver is the only feature requiring threads. */ |
689 | | #ifdef USE_RESOLV_THREADED |
690 | | #define USE_THREADS |
691 | | #endif |
692 | | |
693 | | /* ---------------------------------------------------------------- */ |
694 | | /* resolver specialty compile-time defines */ |
695 | | /* CURLRES_* defines to use in the host*.c sources */ |
696 | | /* ---------------------------------------------------------------- */ |
697 | | |
698 | | /* |
699 | | * Mutually exclusive CURLRES_* definitions. |
700 | | */ |
701 | | #if defined(USE_IPV6) && defined(HAVE_GETADDRINFO) |
702 | | # define CURLRES_IPV6 |
703 | | #elif defined(USE_IPV6) && (defined(_WIN32) || defined(__CYGWIN__)) |
704 | | /* assume on Windows that IPv6 without getaddrinfo is a broken build */ |
705 | | # error "Unexpected build: IPv6 is enabled but getaddrinfo was not found." |
706 | | #else |
707 | | # define CURLRES_IPV4 |
708 | | #endif |
709 | | |
710 | | #ifdef USE_RESOLV_THREADED |
711 | | # define CURLRES_ASYNCH |
712 | | #elif defined(USE_RESOLV_ARES) |
713 | | # define CURLRES_ASYNCH |
714 | | /* now undef the stock libc functions to avoid them being used */ |
715 | | # undef HAVE_GETADDRINFO |
716 | | # undef HAVE_FREEADDRINFO |
717 | | #else |
718 | | # define CURLRES_SYNCH |
719 | | #endif |
720 | | |
721 | | /* ---------------------------------------------------------------- */ |
722 | | |
723 | | #if defined(HAVE_LIBIDN2) && defined(HAVE_IDN2_H) && \ |
724 | | !defined(USE_WIN32_IDN) && !defined(USE_APPLE_IDN) |
725 | | /* The lib and header are present */ |
726 | | #define USE_LIBIDN2 |
727 | | #endif |
728 | | |
729 | | #if defined(USE_LIBIDN2) && (defined(USE_WIN32_IDN) || defined(USE_APPLE_IDN)) |
730 | | #error "libidn2 cannot be enabled with WinIDN or AppleIDN, choose one." |
731 | | #endif |
732 | | |
733 | | #if defined(USE_GNUTLS) || defined(USE_OPENSSL) || defined(USE_MBEDTLS) || \ |
734 | | defined(USE_WOLFSSL) || defined(USE_SCHANNEL) || defined(USE_RUSTLS) |
735 | | #define USE_SSL /* SSL support has been enabled */ |
736 | | #endif |
737 | | |
738 | | #if defined(USE_OPENSSL) && defined(USE_WOLFSSL) |
739 | | #ifndef OPENSSL_COEXIST |
740 | | #define OPENSSL_COEXIST |
741 | | #endif |
742 | | #endif |
743 | | |
744 | | #if defined(USE_WOLFSSL) && defined(USE_GNUTLS) |
745 | | /* Avoid defining unprefixed wolfSSL SHA macros colliding with nettle ones */ |
746 | | #define NO_OLD_WC_NAMES |
747 | | #endif |
748 | | |
749 | | /* Single point where USE_SPNEGO definition might be defined */ |
750 | | #if !defined(CURL_DISABLE_NEGOTIATE_AUTH) && \ |
751 | | (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)) |
752 | | #define USE_SPNEGO |
753 | | #endif |
754 | | |
755 | | /* Single point where USE_KERBEROS5 definition might be defined */ |
756 | | #if !defined(CURL_DISABLE_KERBEROS_AUTH) && \ |
757 | | (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)) |
758 | | #define USE_KERBEROS5 |
759 | | #endif |
760 | | |
761 | | /* Single point where USE_NTLM definition might be defined */ |
762 | | #ifdef CURL_ENABLE_NTLM |
763 | | # if (defined(USE_OPENSSL) && defined(HAVE_DES_ECB_ENCRYPT)) || \ |
764 | | defined(USE_GNUTLS) || \ |
765 | | (defined(USE_MBEDTLS) && defined(HAVE_MBEDTLS_DES_CRYPT_ECB)) || \ |
766 | | defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO) || \ |
767 | | (defined(USE_WOLFSSL) && defined(HAVE_WC_DES_ECBENCRYPT)) |
768 | | # define USE_CURL_NTLM_CORE |
769 | | # endif |
770 | | # if defined(USE_CURL_NTLM_CORE) || defined(USE_WINDOWS_SSPI) |
771 | | # define USE_NTLM |
772 | | # endif |
773 | | #endif |
774 | | |
775 | | #if defined(USE_LIBSSH2) || defined(USE_LIBSSH) |
776 | | #define USE_SSH |
777 | | #endif |
778 | | |
779 | | /* GCC <4.6 does not support '#pragma GCC diagnostic push' and does not support |
780 | | 'pragma GCC diagnostic' inside functions. |
781 | | Use CURL_HAVE_DIAG to guard the above in the curl codebase, instead of |
782 | | defined(__GNUC__) || defined(__clang__). |
783 | | */ |
784 | | #if defined(__clang__) || (defined(__GNUC__) && \ |
785 | | ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)))) |
786 | | #define CURL_HAVE_DIAG |
787 | | #endif |
788 | | |
789 | | /* |
790 | | * Provide a mechanism to silence picky compilers, such as gcc 4.6+. |
791 | | * Parameters should of course normally not be unused, but for example when |
792 | | * we have multiple implementations of the same interface it may happen. |
793 | | */ |
794 | | #if defined(__GNUC__) && ((__GNUC__ >= 3) || \ |
795 | | ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 7))) |
796 | | # define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) |
797 | | #elif defined(__IAR_SYSTEMS_ICC__) && (__VER__ >= 9040001) |
798 | | # define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) |
799 | | #else |
800 | | # define WARN_UNUSED_RESULT |
801 | | #endif |
802 | | |
803 | | /* noreturn attribute */ |
804 | | |
805 | | #ifndef CURL_NORETURN |
806 | | #if (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__clang__) || \ |
807 | | defined(__IAR_SYSTEMS_ICC__) |
808 | | # define CURL_NORETURN __attribute__((__noreturn__)) |
809 | | #elif defined(_MSC_VER) |
810 | | # define CURL_NORETURN __declspec(noreturn) |
811 | | #else |
812 | | # define CURL_NORETURN |
813 | | #endif |
814 | | #endif |
815 | | |
816 | | /* fallthrough attribute */ |
817 | | |
818 | | #ifndef FALLTHROUGH |
819 | | #if (defined(__GNUC__) && __GNUC__ >= 7) || \ |
820 | | (defined(__clang__) && __clang_major__ >= 10) |
821 | 0 | # define FALLTHROUGH() __attribute__((fallthrough)) |
822 | | #else |
823 | | # define FALLTHROUGH() do {} while(0) |
824 | | #endif |
825 | | #endif |
826 | | |
827 | | /* |
828 | | * Inclusion of common header files. |
829 | | */ |
830 | | |
831 | | #include <stdlib.h> |
832 | | #include <string.h> |
833 | | #include <stdarg.h> |
834 | | #include <time.h> |
835 | | #include <errno.h> |
836 | | |
837 | | #ifdef HAVE_SYS_TYPES_H |
838 | | #include <sys/types.h> |
839 | | #endif |
840 | | |
841 | | #include <sys/stat.h> |
842 | | |
843 | | #if !defined(_WIN32) || defined(__MINGW32__) |
844 | | #include <sys/time.h> |
845 | | #endif |
846 | | |
847 | | #ifdef HAVE_IO_H |
848 | | #include <io.h> |
849 | | #endif |
850 | | |
851 | | #ifdef HAVE_FCNTL_H |
852 | | #include <fcntl.h> |
853 | | #endif |
854 | | |
855 | | #if defined(HAVE_STDBOOL_H) && defined(HAVE_BOOL_T) |
856 | | #include <stdbool.h> |
857 | | #endif |
858 | | |
859 | | #ifdef HAVE_UNISTD_H |
860 | | #include <unistd.h> |
861 | | #endif |
862 | | |
863 | | /* Macro to strip 'const' without triggering a compiler warning. |
864 | | Use it for APIs that do not or cannot support the const qualifier. */ |
865 | | #ifdef HAVE_UINTPTR_T |
866 | 0 | #define CURL_UNCONST(p) ((void *)(uintptr_t)(const void *)(p)) |
867 | | #else |
868 | | #define CURL_UNCONST(p) ((void *)(p)) /* Fall back to simple cast */ |
869 | | #endif |
870 | | |
871 | | #ifdef USE_SCHANNEL |
872 | | /* Must set this before <schannel.h> is included directly or indirectly by |
873 | | another Windows header. */ |
874 | | # define SCHANNEL_USE_BLACKLISTS /* for SCH_CREDENTIALS */ |
875 | | # include <subauth.h> /* for [P]UNICODE_STRING in SCH_CREDENTIALS */ |
876 | | #endif |
877 | | |
878 | | #ifdef __hpux |
879 | | # if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL) |
880 | | # ifdef _APP32_64BIT_OFF_T |
881 | | # define OLD_APP32_64BIT_OFF_T _APP32_64BIT_OFF_T |
882 | | # undef _APP32_64BIT_OFF_T |
883 | | # else |
884 | | # undef OLD_APP32_64BIT_OFF_T |
885 | | # endif |
886 | | # endif |
887 | | #endif |
888 | | |
889 | | #ifndef _WIN32 |
890 | | #include <sys/socket.h> /* also for MSG_NOSIGNAL */ |
891 | | #endif |
892 | | |
893 | | #include "functypes.h" |
894 | | |
895 | | #ifdef __hpux |
896 | | # if !defined(_XOPEN_SOURCE_EXTENDED) || defined(_KERNEL) |
897 | | # ifdef OLD_APP32_64BIT_OFF_T |
898 | | # define _APP32_64BIT_OFF_T OLD_APP32_64BIT_OFF_T |
899 | | # undef OLD_APP32_64BIT_OFF_T |
900 | | # endif |
901 | | # endif |
902 | | #endif |
903 | | |
904 | | /* |
905 | | * Definition of timeval struct for platforms that do not have it. |
906 | | */ |
907 | | #ifndef HAVE_STRUCT_TIMEVAL |
908 | | struct timeval { |
909 | | long tv_sec; |
910 | | long tv_usec; |
911 | | }; |
912 | | #endif |
913 | | |
914 | | /* |
915 | | * If we have the MSG_NOSIGNAL define, make sure we use |
916 | | * it as the fourth argument of function send() |
917 | | */ |
918 | | #ifdef MSG_NOSIGNAL |
919 | 0 | #define SEND_4TH_ARG MSG_NOSIGNAL |
920 | | #else |
921 | | #define SEND_4TH_ARG 0 |
922 | | #endif |
923 | | |
924 | | #ifdef __minix |
925 | | /* Minix does not support recv on TCP sockets */ |
926 | | #define sread(x, y, z) (ssize_t)read((RECV_TYPE_ARG1)(x), \ |
927 | | (RECV_TYPE_ARG2)(y), \ |
928 | | (RECV_TYPE_ARG3)(z)) |
929 | | |
930 | | #elif defined(HAVE_RECV) |
931 | | /* |
932 | | * The definitions for the return type and arguments types |
933 | | * of functions recv() and send() belong and come from the |
934 | | * configuration file. Do not define them in any other place. |
935 | | * |
936 | | * HAVE_RECV is defined if you have a function named recv() |
937 | | * which is used to read incoming data from sockets. If your |
938 | | * function has another name then do not define HAVE_RECV. |
939 | | * |
940 | | * If HAVE_RECV is defined then RECV_TYPE_ARG1, RECV_TYPE_ARG2, |
941 | | * RECV_TYPE_ARG3, RECV_TYPE_ARG4 and RECV_TYPE_RETV must also |
942 | | * be defined. |
943 | | * |
944 | | * HAVE_SEND is defined if you have a function named send() |
945 | | * which is used to write outgoing data on a connected socket. |
946 | | * If yours has another name then do not define HAVE_SEND. |
947 | | * |
948 | | * If HAVE_SEND is defined then SEND_TYPE_ARG1, SEND_TYPE_ARG2, |
949 | | * SEND_TYPE_ARG3, SEND_TYPE_ARG4 and SEND_TYPE_RETV must also |
950 | | * be defined. SEND_NONCONST_ARG2 must also be defined if ARG2 |
951 | | * does not accept const. |
952 | | */ |
953 | | |
954 | 0 | #define sread(x, y, z) (ssize_t)recv((RECV_TYPE_ARG1)(x), \ |
955 | 0 | (RECV_TYPE_ARG2)(y), \ |
956 | 0 | (RECV_TYPE_ARG3)(z), \ |
957 | 0 | (RECV_TYPE_ARG4)(0)) |
958 | | #else /* HAVE_RECV */ |
959 | | #ifndef sread |
960 | | #error "Missing definition of macro sread!" |
961 | | #endif |
962 | | #endif /* HAVE_RECV */ |
963 | | |
964 | | #ifdef __minix |
965 | | /* Minix does not support send on TCP sockets */ |
966 | | #define swrite(x, y, z) (ssize_t)write((SEND_TYPE_ARG1)(x), \ |
967 | | (SEND_TYPE_ARG2)CURL_UNCONST(y), \ |
968 | | (SEND_TYPE_ARG3)(z)) |
969 | | #elif defined(HAVE_SEND) |
970 | | #ifdef SEND_NONCONST_ARG2 |
971 | | #define swrite(x, y, z) (ssize_t)send((SEND_TYPE_ARG1)(x), \ |
972 | | (SEND_TYPE_ARG2)CURL_UNCONST(y), \ |
973 | | (SEND_TYPE_ARG3)(z), \ |
974 | | (SEND_TYPE_ARG4)(SEND_4TH_ARG)) |
975 | | #else |
976 | 0 | #define swrite(x, y, z) (ssize_t)send((SEND_TYPE_ARG1)(x), \ |
977 | 0 | (const SEND_TYPE_ARG2)(y), \ |
978 | 0 | (SEND_TYPE_ARG3)(z), \ |
979 | 0 | (SEND_TYPE_ARG4)(SEND_4TH_ARG)) |
980 | | #endif /* SEND_NONCONST_ARG2 */ |
981 | | #else /* HAVE_SEND */ |
982 | | #ifndef swrite |
983 | | #error "Missing definition of macro swrite!" |
984 | | #endif |
985 | | #endif /* HAVE_SEND */ |
986 | | |
987 | | /* |
988 | | * Function-like macro definition used to close a socket. |
989 | | */ |
990 | | #ifdef HAVE_CLOSESOCKET |
991 | | # define CURL_SCLOSE(x) closesocket(x) |
992 | | #elif defined(HAVE_CLOSESOCKET_CAMEL) |
993 | | # define CURL_SCLOSE(x) CloseSocket(x) |
994 | | #elif defined(MSDOS) /* Watt-32 */ |
995 | | # define CURL_SCLOSE(x) close_s(x) |
996 | | #elif defined(USE_LWIPSOCK) |
997 | | # define CURL_SCLOSE(x) lwip_close(x) |
998 | | #else |
999 | 0 | # define CURL_SCLOSE(x) close(x) |
1000 | | #endif |
1001 | | |
1002 | | /* |
1003 | | * Stack-independent version of fcntl() on sockets: |
1004 | | */ |
1005 | | #ifdef USE_LWIPSOCK |
1006 | | # define sfcntl lwip_fcntl |
1007 | | #else |
1008 | 0 | # define sfcntl fcntl |
1009 | | #endif |
1010 | | |
1011 | | /* |
1012 | | * 'bool' stuff compatible with HP-UX headers. |
1013 | | */ |
1014 | | #if defined(__hpux) && !defined(HAVE_BOOL_T) |
1015 | | typedef int bool; |
1016 | | # define false 0 |
1017 | | # define true 1 |
1018 | | # define HAVE_BOOL_T |
1019 | | #endif |
1020 | | |
1021 | | /* |
1022 | | * 'bool' exists on platforms with <stdbool.h>, i.e. C99 platforms. |
1023 | | * On non-C99 platforms there is no bool, so define an enum for that. |
1024 | | * On C99 platforms 'false' and 'true' also exist. Enum uses a |
1025 | | * global namespace though, so use bool_false and bool_true. |
1026 | | */ |
1027 | | #ifndef HAVE_BOOL_T |
1028 | | typedef enum { |
1029 | | bool_false = 0, |
1030 | | bool_true = 1 |
1031 | | } bool; |
1032 | | |
1033 | | /* |
1034 | | * Use a define to let 'true' and 'false' use those enums. There |
1035 | | * are currently no use of true and false in libcurl proper, but |
1036 | | * there are some in the examples. This will cater for any later |
1037 | | * code happening to use true and false. |
1038 | | */ |
1039 | | # define false bool_false |
1040 | | # define true bool_true |
1041 | | # define HAVE_BOOL_T |
1042 | | #endif |
1043 | | |
1044 | | /* the type we use for storing a single boolean bit */ |
1045 | | typedef unsigned int curl_bit; |
1046 | | #define BIT(x) curl_bit x:1 |
1047 | | |
1048 | | /* |
1049 | | * Redefine TRUE and FALSE too, to catch current use. With this |
1050 | | * change, 'bool found = 1' will give a warning on MIPSPro, but |
1051 | | * 'bool found = TRUE' will not. Change tested on IRIX/MIPSPro, |
1052 | | * AIX 5.1/Xlc, Tru64 5.1/cc, w/make test too. |
1053 | | */ |
1054 | | #ifndef TRUE |
1055 | 0 | #define TRUE true |
1056 | | #endif |
1057 | | #ifndef FALSE |
1058 | 1.58k | #define FALSE false |
1059 | | #endif |
1060 | | |
1061 | | #include "curl_ctype.h" |
1062 | | |
1063 | | /* |
1064 | | * Macro used to include code only in debug builds. |
1065 | | */ |
1066 | | #ifdef DEBUGBUILD |
1067 | 0 | #define DEBUGF(x) x |
1068 | | #else |
1069 | | #define DEBUGF(x) do {} while(0) |
1070 | | #endif |
1071 | | |
1072 | | /* |
1073 | | * Macro used to include assertion code only in debug builds. |
1074 | | */ |
1075 | | #undef DEBUGASSERT |
1076 | | #ifdef DEBUGBUILD |
1077 | | #ifdef CURL_DEBUGASSERT |
1078 | | /* External assertion handler for custom integrations */ |
1079 | | #define DEBUGASSERT(x) CURL_DEBUGASSERT(x) |
1080 | | #else |
1081 | 0 | #define DEBUGASSERT(x) assert(x) |
1082 | | #endif |
1083 | | #else |
1084 | | #define DEBUGASSERT(x) do {} while(0) |
1085 | | #endif |
1086 | | |
1087 | | /* |
1088 | | * Macro SOCKERRNO / SET_SOCKERRNO() returns / sets the *socket-related* errno |
1089 | | * (or equivalent) on this platform to hide platform details to code using it. |
1090 | | */ |
1091 | | #ifdef USE_WINSOCK |
1092 | | #define SOCKERRNO ((int)WSAGetLastError()) |
1093 | | #define SET_SOCKERRNO(x) WSASetLastError((int)(x)) |
1094 | | #else |
1095 | 0 | #define SOCKERRNO errno |
1096 | 0 | #define SET_SOCKERRNO(x) (errno = (x)) |
1097 | | #endif |
1098 | | |
1099 | | /* |
1100 | | * Portable error number symbolic names defined to Winsock error codes. |
1101 | | */ |
1102 | | #ifdef USE_WINSOCK |
1103 | | #define SOCKEACCES WSAEACCES |
1104 | | #define SOCKEADDRINUSE WSAEADDRINUSE |
1105 | | #define SOCKEADDRNOTAVAIL WSAEADDRNOTAVAIL |
1106 | | #define SOCKEAFNOSUPPORT WSAEAFNOSUPPORT |
1107 | | #define SOCKEBADF WSAEBADF |
1108 | | #define SOCKECONNREFUSED WSAECONNREFUSED |
1109 | | #define SOCKECONNRESET WSAECONNRESET |
1110 | | #define SOCKEINPROGRESS WSAEINPROGRESS |
1111 | | #define SOCKEINTR WSAEINTR |
1112 | | #define SOCKEINVAL WSAEINVAL |
1113 | | #define SOCKEISCONN WSAEISCONN |
1114 | | #define SOCKEMSGSIZE WSAEMSGSIZE |
1115 | | /* Use literal value to work around clang-tidy <=20 misreporting |
1116 | | 'readability-uppercase-literal-suffix' with mingw-w64 headers */ |
1117 | | #define SOCKENOMEM 8L /* WSA_NOT_ENOUGH_MEMORY */ |
1118 | | #define SOCKETIMEDOUT WSAETIMEDOUT |
1119 | | #define SOCKEWOULDBLOCK WSAEWOULDBLOCK |
1120 | | #else |
1121 | 0 | #define SOCKEACCES EACCES |
1122 | 0 | #define SOCKEADDRINUSE EADDRINUSE |
1123 | 0 | #define SOCKEADDRNOTAVAIL EADDRNOTAVAIL |
1124 | 0 | #define SOCKEAFNOSUPPORT EAFNOSUPPORT |
1125 | | #define SOCKEBADF EBADF |
1126 | | #define SOCKECONNREFUSED ECONNREFUSED |
1127 | 0 | #define SOCKECONNRESET ECONNRESET |
1128 | 0 | #define SOCKEINPROGRESS EINPROGRESS |
1129 | 0 | #define SOCKEINTR EINTR |
1130 | | #define SOCKEINVAL EINVAL |
1131 | 0 | #define SOCKEISCONN EISCONN |
1132 | | #define SOCKEMSGSIZE EMSGSIZE |
1133 | 0 | #define SOCKENOMEM ENOMEM |
1134 | | #ifdef ETIMEDOUT |
1135 | 0 | #define SOCKETIMEDOUT ETIMEDOUT |
1136 | | #endif |
1137 | 0 | #define SOCKEWOULDBLOCK EWOULDBLOCK |
1138 | | #endif |
1139 | | |
1140 | | /* |
1141 | | * Macro argv_item_t hides platform details to code using it. |
1142 | | */ |
1143 | | #ifdef __VMS |
1144 | | #define argv_item_t __char_ptr32 |
1145 | | #elif defined(_UNICODE) |
1146 | | #define argv_item_t wchar_t * |
1147 | | #else |
1148 | | #define argv_item_t char * |
1149 | | #endif |
1150 | | |
1151 | | /* |
1152 | | * We use this ZERO_NULL to avoid picky compiler warnings, |
1153 | | * when assigning a NULL pointer to a function pointer var. |
1154 | | */ |
1155 | 0 | #define ZERO_NULL 0 |
1156 | | |
1157 | | /* |
1158 | | * Macros and functions to safely suppress warnings |
1159 | | */ |
1160 | | #include "curlx/warnless.h" |
1161 | | |
1162 | | #ifdef _WIN32 |
1163 | | # undef read |
1164 | | # define read(fd, buf, count) (ssize_t)_read(fd, buf, curlx_uztoui(count)) |
1165 | | # undef write |
1166 | | # define write(fd, buf, count) (ssize_t)_write(fd, buf, curlx_uztoui(count)) |
1167 | | /* Avoid VS2005+ _CRT_NONSTDC_NO_DEPRECATE warnings about non-portable funcs */ |
1168 | | # undef fileno |
1169 | | # define fileno(fh) _fileno(fh) |
1170 | | # undef unlink |
1171 | | # define unlink(fn) _unlink(fn) |
1172 | | # undef isatty |
1173 | | # define isatty(fd) _isatty(fd) |
1174 | | #endif |
1175 | | |
1176 | | /* |
1177 | | * Definition of our NOP statement Object-like macro |
1178 | | */ |
1179 | | #ifndef Curl_nop_stmt |
1180 | 0 | #define Curl_nop_stmt do {} while(0) |
1181 | | #endif |
1182 | | |
1183 | | /* |
1184 | | * Ensure that Winsock and lwIP TCP/IP stacks are not mixed. |
1185 | | */ |
1186 | | #if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H) |
1187 | | # if defined(SOCKET) || defined(USE_WINSOCK) |
1188 | | # error "Winsock and lwIP TCP/IP stack definitions shall not coexist!" |
1189 | | # endif |
1190 | | #endif |
1191 | | |
1192 | | /* |
1193 | | * shutdown() flags for systems that do not define them |
1194 | | */ |
1195 | | #ifndef SHUT_RD |
1196 | | #define SHUT_RD 0x00 |
1197 | | #endif |
1198 | | |
1199 | | #ifndef SHUT_WR |
1200 | | #define SHUT_WR 0x01 |
1201 | | #endif |
1202 | | |
1203 | | #ifndef SHUT_RDWR |
1204 | | #define SHUT_RDWR 0x02 |
1205 | | #endif |
1206 | | |
1207 | | /* Define S_ISREG if not defined by system headers, e.g. MSVC */ |
1208 | | #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG) |
1209 | | #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) |
1210 | | #endif |
1211 | | |
1212 | | /* Define S_ISDIR if not defined by system headers, e.g. MSVC */ |
1213 | | #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR) |
1214 | | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) |
1215 | | #endif |
1216 | | |
1217 | | /* For MSVC (all versions as of VS2022) */ |
1218 | | #ifndef STDIN_FILENO |
1219 | | #define STDIN_FILENO fileno(stdin) |
1220 | | #endif |
1221 | | #ifndef STDOUT_FILENO |
1222 | | #define STDOUT_FILENO fileno(stdout) |
1223 | | #endif |
1224 | | #ifndef STDERR_FILENO |
1225 | | #define STDERR_FILENO fileno(stderr) |
1226 | | #endif |
1227 | | |
1228 | | /* Since O_BINARY is used in bitmasks, setting it to zero makes it usable in |
1229 | | source code but yet it does not ruin anything */ |
1230 | | #ifdef _O_BINARY /* for _WIN32 || MSDOS */ |
1231 | | #define CURL_O_BINARY _O_BINARY |
1232 | | #elif defined(O_BINARY) /* __CYGWIN__ */ |
1233 | | #define CURL_O_BINARY O_BINARY |
1234 | | #else |
1235 | 0 | #define CURL_O_BINARY 0 |
1236 | | #endif |
1237 | | |
1238 | | /* Requires io.h when available */ |
1239 | | #ifdef MSDOS |
1240 | | #define CURL_BINMODE(stream) (void)setmode(fileno(stream), CURL_O_BINARY) |
1241 | | #elif defined(_WIN32) || defined(__CYGWIN__) |
1242 | | #define CURL_BINMODE(stream) (void)_setmode(fileno(stream), CURL_O_BINARY) |
1243 | | #else |
1244 | | #define CURL_BINMODE(stream) (void)(stream) |
1245 | | #endif |
1246 | | |
1247 | | /* In Windows the default file mode is text but an application can override it. |
1248 | | Therefore we specify it explicitly. https://github.com/curl/curl/pull/258 |
1249 | | */ |
1250 | | #if defined(_WIN32) || defined(MSDOS) |
1251 | | #define FOPEN_READTEXT "rt" |
1252 | | #define FOPEN_WRITETEXT "wt" |
1253 | | #define FOPEN_APPENDTEXT "at" |
1254 | | #elif defined(__CYGWIN__) |
1255 | | /* Cygwin has specific behavior we need to address when _WIN32 is not defined. |
1256 | | https://cygwin.com/cygwin-ug-net/using-textbinary.html |
1257 | | For write we want our output to have line endings of LF and be compatible with |
1258 | | other Cygwin utilities. For read we want to handle input that may have line |
1259 | | endings either CRLF or LF so 't' is appropriate. |
1260 | | */ |
1261 | | #define FOPEN_READTEXT "rt" |
1262 | | #define FOPEN_WRITETEXT "w" |
1263 | | #define FOPEN_APPENDTEXT "a" |
1264 | | #else |
1265 | | #define FOPEN_READTEXT "r" |
1266 | 0 | #define FOPEN_WRITETEXT "w" |
1267 | | #define FOPEN_APPENDTEXT "a" |
1268 | | #endif |
1269 | | |
1270 | | /* for systems that do not detect this in configure */ |
1271 | | #ifndef CURL_SA_FAMILY_T |
1272 | | # ifdef USE_WINSOCK |
1273 | | # define CURL_SA_FAMILY_T ADDRESS_FAMILY |
1274 | | # elif defined(HAVE_SA_FAMILY_T) |
1275 | 0 | # define CURL_SA_FAMILY_T sa_family_t |
1276 | | # elif defined(__AMIGA__) |
1277 | | # define CURL_SA_FAMILY_T unsigned char |
1278 | | # else |
1279 | | /* use a sensible default */ |
1280 | | # define CURL_SA_FAMILY_T unsigned short |
1281 | | # endif |
1282 | | #endif |
1283 | | |
1284 | | /* Some convenience macros to get the larger/smaller value out of two given. |
1285 | | We prefix with CURL to prevent name collisions. */ |
1286 | 0 | #define CURLMAX(x, y) ((x) > (y) ? (x) : (y)) |
1287 | 0 | #define CURLMIN(x, y) ((x) < (y) ? (x) : (y)) |
1288 | | |
1289 | | /* A convenience macro to provide both the string literal and the length of |
1290 | | the string literal in one go, useful for functions that take "string,len" |
1291 | | as their argument */ |
1292 | 3.90k | #define STRCONST(x) x, sizeof(x) - 1 |
1293 | | |
1294 | 0 | #define CURL_ARRAYSIZE(A) (sizeof(A) / sizeof((A)[0])) |
1295 | | |
1296 | | /* Buffer size for error messages retrieved via |
1297 | | curlx_strerror() and Curl_sspi_strerror() */ |
1298 | | #define STRERROR_LEN 256 |
1299 | | |
1300 | | #ifndef CURL_DID_MEMORY_FUNC_TYPEDEFS /* only if not already done */ |
1301 | | /* |
1302 | | * The following memory function replacement typedef's are COPIED from |
1303 | | * curl/curl.h and MUST match the originals. We copy them to avoid having to |
1304 | | * include curl/curl.h here. We avoid that include since it includes stdio.h |
1305 | | * and other headers that may get messed up with defines done here. |
1306 | | */ |
1307 | | typedef void *(*curl_malloc_callback)(size_t size); |
1308 | | typedef void (*curl_free_callback)(void *ptr); |
1309 | | typedef void *(*curl_realloc_callback)(void *ptr, size_t size); |
1310 | | typedef char *(*curl_strdup_callback)(const char *str); |
1311 | | typedef void *(*curl_calloc_callback)(size_t nmemb, size_t size); |
1312 | | #define CURL_DID_MEMORY_FUNC_TYPEDEFS |
1313 | | #endif |
1314 | | |
1315 | | extern curl_malloc_callback Curl_cmalloc; |
1316 | | extern curl_free_callback Curl_cfree; |
1317 | | extern curl_realloc_callback Curl_crealloc; |
1318 | | extern curl_strdup_callback Curl_cstrdup; |
1319 | | extern curl_calloc_callback Curl_ccalloc; |
1320 | | |
1321 | | /* |
1322 | | * curlx_safefree() defined as a macro to allow MemoryTracking feature |
1323 | | * to log free() calls at same location where curlx_safefree() is used. |
1324 | | * This macro also assigns NULL to given pointer when free'd. |
1325 | | */ |
1326 | | #define curlx_safefree(ptr) \ |
1327 | 793 | do { \ |
1328 | 793 | curlx_free(ptr); \ |
1329 | 793 | (ptr) = NULL; \ |
1330 | 793 | } while(0) |
1331 | | |
1332 | | /* Same as curlx_safefree() but zeroes memory before freeing */ |
1333 | | #define curlx_safefreezero(ptr, size) \ |
1334 | | do { \ |
1335 | | curlx_freezero(ptr, size); \ |
1336 | | (ptr) = NULL; \ |
1337 | | } while(0) |
1338 | | |
1339 | | /* Same as curlx_safefreezero() but determines length with strlen() */ |
1340 | | #define curlx_safefreezeroz(ptr) \ |
1341 | | do { \ |
1342 | | curlx_freezeroz(ptr); \ |
1343 | | (ptr) = NULL; \ |
1344 | | } while(0) |
1345 | | |
1346 | | #include <curl/curl.h> /* for CURL_EXTERN, curl_socket_t, mprintf.h */ |
1347 | | |
1348 | | #ifdef DEBUGBUILD |
1349 | | #define CURL_MEMDEBUG |
1350 | | #endif |
1351 | | |
1352 | | #ifdef CURL_MEMDEBUG |
1353 | | #ifdef __clang__ |
1354 | | # define ALLOC_FUNC __attribute__((__malloc__)) |
1355 | | # if __clang_major__ >= 4 |
1356 | | # define ALLOC_SIZE(s) __attribute__((__alloc_size__(s))) |
1357 | | # define ALLOC_SIZE2(n, s) __attribute__((__alloc_size__(n, s))) |
1358 | | # else |
1359 | | # define ALLOC_SIZE(s) |
1360 | | # define ALLOC_SIZE2(n, s) |
1361 | | # endif |
1362 | | #elif defined(__GNUC__) && __GNUC__ >= 3 |
1363 | | # define ALLOC_FUNC __attribute__((__malloc__)) |
1364 | | # define ALLOC_SIZE(s) __attribute__((__alloc_size__(s))) |
1365 | | # define ALLOC_SIZE2(n, s) __attribute__((__alloc_size__(n, s))) |
1366 | | #elif defined(_MSC_VER) |
1367 | | # define ALLOC_FUNC __declspec(restrict) |
1368 | | # define ALLOC_SIZE(s) |
1369 | | # define ALLOC_SIZE2(n, s) |
1370 | | #else |
1371 | | # define ALLOC_FUNC |
1372 | | # define ALLOC_SIZE(s) |
1373 | | # define ALLOC_SIZE2(n, s) |
1374 | | #endif |
1375 | | |
1376 | | extern FILE *curl_dbg_logfile; |
1377 | | |
1378 | | /* memory functions */ |
1379 | | CURL_EXTERN void curl_dbg_free(void *ptr, int line, const char *source); |
1380 | | CURL_EXTERN ALLOC_FUNC ALLOC_SIZE(1) |
1381 | | void *curl_dbg_malloc(size_t size, int line, const char *source); |
1382 | | CURL_EXTERN ALLOC_FUNC ALLOC_SIZE2(1, 2) |
1383 | | void *curl_dbg_calloc(size_t n, size_t size, int line, const char *source); |
1384 | | CURL_EXTERN ALLOC_SIZE(2) |
1385 | | void *curl_dbg_realloc(void *ptr, size_t size, int line, const char *source); |
1386 | | CURL_EXTERN ALLOC_FUNC |
1387 | | char *curl_dbg_strdup(const char *str, int line, const char *src); |
1388 | | #if defined(_WIN32) && defined(UNICODE) |
1389 | | CURL_EXTERN ALLOC_FUNC |
1390 | | wchar_t *curl_dbg_wcsdup(const wchar_t *str, int line, const char *source); |
1391 | | #endif |
1392 | | |
1393 | | CURL_EXTERN void curl_dbg_memdebug(const char *logname); |
1394 | | CURL_EXTERN void curl_dbg_memlimit(long limit); |
1395 | | CURL_EXTERN void curl_dbg_log(const char *format, ...) CURL_PRINTF(1, 2); |
1396 | | |
1397 | | /* file descriptor manipulators */ |
1398 | | CURL_EXTERN curl_socket_t curl_dbg_socket(int domain, int type, int protocol, |
1399 | | int line, const char *source); |
1400 | | CURL_EXTERN void curl_dbg_mark_sclose(curl_socket_t sockfd, |
1401 | | int line, const char *source); |
1402 | | CURL_EXTERN int curl_dbg_sclose(curl_socket_t sockfd, |
1403 | | int line, const char *source); |
1404 | | CURL_EXTERN curl_socket_t curl_dbg_accept(curl_socket_t s, |
1405 | | void *saddr, void *saddrlen, |
1406 | | int line, const char *source); |
1407 | | #ifdef HAVE_ACCEPT4 |
1408 | | CURL_EXTERN curl_socket_t curl_dbg_accept4(curl_socket_t s, void *saddr, |
1409 | | void *saddrlen, int flags, |
1410 | | int line, const char *source); |
1411 | | #endif |
1412 | | #ifdef HAVE_SOCKETPAIR |
1413 | | CURL_EXTERN int curl_dbg_socketpair(int domain, int type, int protocol, |
1414 | | curl_socket_t socket_vector[2], |
1415 | | int line, const char *source); |
1416 | | #endif |
1417 | | |
1418 | | /* FILE functions */ |
1419 | | CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source); |
1420 | | CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fopen(const char *file, const char *mode, |
1421 | | int line, const char *source); |
1422 | | CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_freopen(const char *file, |
1423 | | const char *mode, FILE *fh, |
1424 | | int line, const char *source); |
1425 | | CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode, |
1426 | | int line, const char *source); |
1427 | | |
1428 | 0 | #define sclose(sockfd) curl_dbg_sclose(sockfd, __LINE__, __FILE__) |
1429 | | #define fake_sclose(sockfd) curl_dbg_mark_sclose(sockfd, __LINE__, __FILE__) |
1430 | | |
1431 | | #define CURL_GETADDRINFO(host, serv, hint, res) \ |
1432 | 0 | curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__) |
1433 | | #define CURL_FREEADDRINFO(data) \ |
1434 | 0 | curl_dbg_freeaddrinfo(data, __LINE__, __FILE__) |
1435 | | #define CURL_SOCKET(domain, type, protocol) \ |
1436 | 0 | curl_dbg_socket((int)(domain), type, protocol, __LINE__, __FILE__) |
1437 | | #ifdef HAVE_SOCKETPAIR |
1438 | | #define CURL_SOCKETPAIR(domain, type, protocol, socket_vector) \ |
1439 | | curl_dbg_socketpair((int)(domain), type, protocol, socket_vector, \ |
1440 | | __LINE__, __FILE__) |
1441 | | #endif |
1442 | | #define CURL_ACCEPT(sock, addr, len) \ |
1443 | | curl_dbg_accept(sock, addr, len, __LINE__, __FILE__) |
1444 | | #ifdef HAVE_ACCEPT4 |
1445 | | #define CURL_ACCEPT4(sock, addr, len, flags) \ |
1446 | 0 | curl_dbg_accept4(sock, addr, len, flags, __LINE__, __FILE__) |
1447 | | #endif |
1448 | | |
1449 | | #else /* !CURL_MEMDEBUG */ |
1450 | | |
1451 | | #define sclose(x) CURL_SCLOSE(x) |
1452 | | #define fake_sclose(x) Curl_nop_stmt |
1453 | | |
1454 | | #define CURL_GETADDRINFO getaddrinfo |
1455 | | #define CURL_FREEADDRINFO freeaddrinfo |
1456 | | #define CURL_SOCKET socket |
1457 | | #ifdef HAVE_SOCKETPAIR |
1458 | | #define CURL_SOCKETPAIR socketpair |
1459 | | #endif |
1460 | | #define CURL_ACCEPT accept |
1461 | | #ifdef HAVE_ACCEPT4 |
1462 | | #define CURL_ACCEPT4 accept4 |
1463 | | #endif |
1464 | | |
1465 | | #endif /* CURL_MEMDEBUG */ |
1466 | | |
1467 | | /* Allocator macros */ |
1468 | | |
1469 | | #ifdef _WIN32 |
1470 | | #define CURLX_STRDUP_LOW _strdup |
1471 | | #else |
1472 | 0 | #define CURLX_STRDUP_LOW strdup |
1473 | | #endif |
1474 | | |
1475 | | #ifdef CURL_MEMDEBUG |
1476 | | |
1477 | 0 | #define curlx_strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__) |
1478 | 0 | #define curlx_malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__) |
1479 | | #define curlx_calloc(nbelem, size) \ |
1480 | 0 | curl_dbg_calloc(nbelem, size, __LINE__, __FILE__) |
1481 | | #define curlx_realloc(ptr, size) \ |
1482 | 790 | curl_dbg_realloc(ptr, size, __LINE__, __FILE__) |
1483 | 793 | #define curlx_free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__) |
1484 | | |
1485 | | #ifdef _WIN32 |
1486 | | #ifdef UNICODE |
1487 | | #define curlx_tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__) |
1488 | | #else |
1489 | | #define curlx_tcsdup curlx_strdup |
1490 | | #endif |
1491 | | #endif /* _WIN32 */ |
1492 | | |
1493 | | #else /* !CURL_MEMDEBUG */ |
1494 | | |
1495 | | #ifdef BUILDING_LIBCURL |
1496 | | #define curlx_strdup Curl_cstrdup |
1497 | | #define curlx_malloc Curl_cmalloc |
1498 | | #define curlx_calloc Curl_ccalloc |
1499 | | #define curlx_realloc Curl_crealloc |
1500 | | #define curlx_free Curl_cfree |
1501 | | #else /* !BUILDING_LIBCURL */ |
1502 | | #define curlx_strdup CURLX_STRDUP_LOW |
1503 | | #define curlx_malloc malloc |
1504 | | #define curlx_calloc calloc |
1505 | | #define curlx_realloc realloc |
1506 | | #define curlx_free free |
1507 | | #endif /* BUILDING_LIBCURL */ |
1508 | | |
1509 | | #ifdef _WIN32 |
1510 | | #ifdef UNICODE |
1511 | | #define curlx_tcsdup curlx_wcsdup |
1512 | | #else |
1513 | | #define curlx_tcsdup curlx_strdup |
1514 | | #endif |
1515 | | #endif /* _WIN32 */ |
1516 | | |
1517 | | #endif /* CURL_MEMDEBUG */ |
1518 | | |
1519 | | /* Some versions of the Android NDK is missing the declaration */ |
1520 | | #if defined(HAVE_GETPWUID_R) && \ |
1521 | | defined(__ANDROID_API__) && (__ANDROID_API__ < 21) |
1522 | | struct passwd; |
1523 | | int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, |
1524 | | size_t buflen, struct passwd **result); |
1525 | | #endif |
1526 | | |
1527 | | #ifdef UNITTESTS |
1528 | | #define UNITTEST |
1529 | | #else |
1530 | | #define UNITTEST static |
1531 | | #endif |
1532 | | |
1533 | | #ifdef USE_NGHTTP2 |
1534 | | #define USE_HTTP2 |
1535 | | #endif |
1536 | | |
1537 | | #if (defined(USE_NGTCP2) && defined(USE_NGHTTP3)) || defined(USE_QUICHE) |
1538 | | |
1539 | | #ifdef CURL_WITH_MULTI_SSL |
1540 | | #error "MultiSSL combined with QUIC is not supported" |
1541 | | #endif |
1542 | | |
1543 | | #define USE_HTTP3 |
1544 | | #endif |
1545 | | |
1546 | | /* WebAssembly builds have TCP_NODELAY, but runtime support is missing. */ |
1547 | | #ifndef __EMSCRIPTEN__ |
1548 | | #define CURL_TCP_NODELAY_SUPPORTED |
1549 | | #endif |
1550 | | |
1551 | | /* Certain Windows implementations are not aligned with what curl expects, |
1552 | | so always use the local one on this platform. E.g. the mingw-w64 |
1553 | | implementation can return wrong results for non-ASCII inputs. */ |
1554 | | #if defined(HAVE_BASENAME) && defined(_WIN32) |
1555 | | #undef HAVE_BASENAME |
1556 | | #endif |
1557 | | |
1558 | | #if defined(USE_UNIX_SOCKETS) && defined(_WIN32) |
1559 | | /* Offered by mingw-w64 v10+, MS SDK 10.0.16299.0/VS2017 15.4+ */ |
1560 | | #if defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR >= 10) |
1561 | | # include <afunix.h> |
1562 | | #elif !defined(UNIX_PATH_MAX) /* Replicate logic present in afunix.h */ |
1563 | | # define UNIX_PATH_MAX 108 |
1564 | | /* !checksrc! disable TYPEDEFSTRUCT 1 */ |
1565 | | typedef struct sockaddr_un { |
1566 | | CURL_SA_FAMILY_T sun_family; |
1567 | | char sun_path[UNIX_PATH_MAX]; |
1568 | | } SOCKADDR_UN, *PSOCKADDR_UN; |
1569 | | #endif |
1570 | | #endif |
1571 | | |
1572 | | #ifdef USE_OPENSSL |
1573 | | /* OpenSSL 3 marks these functions deprecated but we have no replacements (yet) |
1574 | | so tell the compiler to not warn for them: |
1575 | | - DES_* (for NTLM), SSL_CTX_set_srp_* (for TLS-SRP) |
1576 | | - EVP_PKEY_get1_RSA, MD5_*, RSA_flags, RSA_free (auto-skipped for OpenSSL |
1577 | | built with no-deprecated) */ |
1578 | | # define OPENSSL_SUPPRESS_DEPRECATED |
1579 | | # ifdef _WIN32 |
1580 | | /* Silence LibreSSL warnings about wincrypt.h collision. Works in 3.8.2+ */ |
1581 | | # ifndef LIBRESSL_DISABLE_OVERRIDE_WINCRYPT_DEFINES_WARNING |
1582 | | # define LIBRESSL_DISABLE_OVERRIDE_WINCRYPT_DEFINES_WARNING |
1583 | | # endif |
1584 | | # endif |
1585 | | #endif |
1586 | | |
1587 | | #ifdef CURL_INLINE |
1588 | | /* 'CURL_INLINE' defined, use as-is */ |
1589 | | #elif defined(inline) |
1590 | | # define CURL_INLINE inline /* 'inline' defined, assumed correct */ |
1591 | | #elif defined(__cplusplus) |
1592 | | /* The code is compiled with C++ compiler. |
1593 | | C++ always supports 'inline'. */ |
1594 | | # define CURL_INLINE inline /* 'inline' keyword supported */ |
1595 | | #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L |
1596 | | /* C99 (and later) supports 'inline' keyword */ |
1597 | | # define CURL_INLINE inline /* 'inline' keyword supported */ |
1598 | | #elif defined(__GNUC__) && __GNUC__ >= 3 |
1599 | | /* GCC supports '__inline__' as an extension */ |
1600 | | # define CURL_INLINE __inline__ |
1601 | | #elif defined(_MSC_VER) |
1602 | | # define CURL_INLINE __inline |
1603 | | #else |
1604 | | /* Probably 'inline' is not supported by compiler. |
1605 | | Define to the empty string to be on the safe side. */ |
1606 | | # define CURL_INLINE /* empty */ |
1607 | | #endif |
1608 | | |
1609 | | /* Detect if compiler supports C99 variadic macros */ |
1610 | | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ |
1611 | | defined(_MSC_VER) |
1612 | | #define CURL_HAVE_MACRO_VARARG |
1613 | | #endif |
1614 | | |
1615 | | #if !defined(CURL_HAVE_MACRO_VARARG) || \ |
1616 | | (defined(CURL_HAVE_MACRO_VARARG) && !defined(CURL_DISABLE_VERBOSE_STRINGS)) |
1617 | | #define CURLVERBOSE |
1618 | 0 | #define VERBOSE(x) x |
1619 | 0 | #define NOVERBOSE(x) Curl_nop_stmt |
1620 | | #else |
1621 | | #define VERBOSE(x) Curl_nop_stmt |
1622 | | #define NOVERBOSE(x) x |
1623 | | #endif |
1624 | | |
1625 | | /* For FreeBSD it is included from curl/curl.h */ |
1626 | | #if defined(__DragonFly__) || defined(__OpenBSD__) || defined(__NetBSD__) |
1627 | | #include <sys/param.h> /* for __DragonFly_version, OpenBSD, |
1628 | | __NetBSD_Version__ */ |
1629 | | #endif |
1630 | | |
1631 | | #ifndef _CURL_LOCAL_MEMZERO /* to be removed after a couple of releases */ |
1632 | | #ifdef _WIN32 |
1633 | | #if defined(_MSC_VER) && defined(NTDDI_VERSION) && \ |
1634 | | (NTDDI_VERSION >= 0x0A000010) /* MS SDK 10.0.26100.0+ */ |
1635 | | #pragma comment(lib, "volatileaccessu.lib") |
1636 | | #define curlx_memzero(buf, size) SecureZeroMemory2(buf, size) |
1637 | | #else |
1638 | | #define curlx_memzero(buf, size) SecureZeroMemory(buf, size) |
1639 | | #endif |
1640 | | #elif defined(HAVE_MEMSET_S) |
1641 | | #define curlx_memzero(buf, size) (void)memset_s(buf, size, 0, size) |
1642 | | #elif defined(HAVE_MEMSET_EXPLICIT) |
1643 | | #define curlx_memzero(buf, size) (void)memset_explicit(buf, 0, size) |
1644 | | #elif defined(__CYGWIN__) || defined(__NEWLIB__) || \ |
1645 | | (defined(__GLIBC__) && \ |
1646 | | (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25))) || \ |
1647 | | (defined(__DragonFly__) && __DragonFly_version >= 500600 /* v5.6+ */) || \ |
1648 | | (defined(__FreeBSD__) && __FreeBSD_version >= 1100037 /* v11.0+ */) || \ |
1649 | | (defined(__OpenBSD__) && OpenBSD >= 201405 /* v5.5+ */) |
1650 | 0 | #define curlx_memzero(buf, size) explicit_bzero(buf, size) |
1651 | | #elif defined(__NetBSD__) && __NetBSD_Version__ >= 702000000 /* v7.2+ */ |
1652 | | #define curlx_memzero(buf, size) (void)explicit_memset(buf, 0, size) |
1653 | | #endif |
1654 | | #endif /* !_CURL_LOCAL_MEMZERO */ |
1655 | | |
1656 | | #ifndef curlx_memzero |
1657 | | #define USE_CURLX_MEMZERO |
1658 | | void curlx_memzero(void *buf, size_t size); |
1659 | | #endif |
1660 | | void curlx_freezero(void *buf, size_t size); |
1661 | | void curlx_freezeroz(void *buf); |
1662 | | |
1663 | | #endif /* HEADER_CURL_SETUP_H */ |