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