1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 * SPDX-License-Identifier: curl
23 ***************************************************************************/
24 #ifdef TIME_WITH_SYS_TIME
25 /* Time with sys/time test */
27 #include <sys/types.h>
42 #ifdef HAVE_FCNTL_O_NONBLOCK
44 /* headers for FCNTL_O_NONBLOCK test */
45 #include <sys/types.h>
49 #if defined(sun) || defined(__sun__) || \
50 defined(__SUNPRO_C) || defined(__SUNPRO_CC)
51 # if defined(__SVR4) || defined(__srv4__)
52 # define PLATFORM_SOLARIS
54 # define PLATFORM_SUNOS4
57 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
58 # define PLATFORM_AIX_V3
61 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3)
62 #error "O_NONBLOCK does not work on this platform"
68 /* O_NONBLOCK source test */
70 if(0 != fcntl(0, F_SETFL, flags | O_NONBLOCK))
76 /* tests for gethostbyname_r */
77 #if defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT) || \
78 defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) || \
79 defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
81 /* no idea whether _REENTRANT is always set, just invent a new flag */
82 # define TEST_GETHOSTBYFOO_REENTRANT
84 #if defined(HAVE_GETHOSTBYNAME_R_3) || \
85 defined(HAVE_GETHOSTBYNAME_R_5) || \
86 defined(HAVE_GETHOSTBYNAME_R_6) || \
87 defined(TEST_GETHOSTBYFOO_REENTRANT)
88 #include <sys/types.h>
92 char *address = "example.com";
97 #if defined(HAVE_GETHOSTBYNAME_R_3) || \
98 defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT)
99 struct hostent_data hdata;
100 #elif defined(HAVE_GETHOSTBYNAME_R_5) || \
101 defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) || \
102 defined(HAVE_GETHOSTBYNAME_R_6) || \
103 defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
109 #if defined(HAVE_GETHOSTBYNAME_R_3) || \
110 defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT)
111 rc = gethostbyname_r(address, &h, &hdata);
112 #elif defined(HAVE_GETHOSTBYNAME_R_5) || \
113 defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT)
114 rc = gethostbyname_r(address, &h, buffer, 8192, &h_errnop);
115 (void)hp; /* not used for test */
116 #elif defined(HAVE_GETHOSTBYNAME_R_6) || \
117 defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
118 rc = gethostbyname_r(address, &h, buffer, 8192, &hp, &h_errnop);
128 #ifdef HAVE_SOCKLEN_T
130 #include <ws2tcpip.h>
132 #include <sys/types.h>
133 #include <sys/socket.h>
140 if (sizeof (socklen_t))
146 #ifdef HAVE_IN_ADDR_T
147 #include <sys/types.h>
148 #include <sys/socket.h>
149 #include <arpa/inet.h>
156 if (sizeof (in_addr_t))
164 #ifdef HAVE_SYS_TYPES_H
165 #include <sys/types.h>
167 #ifdef HAVE_STDBOOL_H
173 if (sizeof (bool *) )
185 int main() { return 0; }
187 #ifdef HAVE_FILE_OFFSET_BITS
188 #ifdef _FILE_OFFSET_BITS
189 #undef _FILE_OFFSET_BITS
191 #define _FILE_OFFSET_BITS 64
192 #include <sys/types.h>
193 /* Check that off_t can represent 2**63 - 1 correctly.
194 We can't simply define LARGE_OFF_T to be 9223372036854775807,
195 since some C++ compilers masquerading as C compilers
196 incorrectly reject 9223372036854775807. */
197 #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
198 int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
199 && LARGE_OFF_T % 2147483647 == 1)
201 int main () { ; return 0; }
203 #ifdef HAVE_IOCTLSOCKET
205 #ifdef HAVE_WINDOWS_H
206 # ifndef WIN32_LEAN_AND_MEAN
207 # define WIN32_LEAN_AND_MEAN
209 # include <windows.h>
210 # ifdef HAVE_WINSOCK2_H
211 # include <winsock2.h>
219 /* ioctlsocket source code */
221 unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
228 #ifdef HAVE_IOCTLSOCKET_CAMEL
230 #ifdef HAVE_WINDOWS_H
231 # ifndef WIN32_LEAN_AND_MEAN
232 # define WIN32_LEAN_AND_MEAN
234 # include <windows.h>
235 # ifdef HAVE_WINSOCK2_H
236 # include <winsock2.h>
244 /* IoctlSocket source code */
245 if(0 != IoctlSocket(0, 0, 0))
251 #ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO
253 #ifdef HAVE_WINDOWS_H
254 # ifndef WIN32_LEAN_AND_MEAN
255 # define WIN32_LEAN_AND_MEAN
257 # include <windows.h>
258 # ifdef HAVE_WINSOCK2_H
259 # include <winsock2.h>
267 /* IoctlSocket source code */
269 if(0 != IoctlSocket(0, FIONBIO, &flags))
275 #ifdef HAVE_IOCTLSOCKET_FIONBIO
277 #ifdef HAVE_WINDOWS_H
278 # ifndef WIN32_LEAN_AND_MEAN
279 # define WIN32_LEAN_AND_MEAN
281 # include <windows.h>
282 # ifdef HAVE_WINSOCK2_H
283 # include <winsock2.h>
292 if(0 != ioctlsocket(0, FIONBIO, &flags))
299 #ifdef HAVE_IOCTL_FIONBIO
300 /* headers for FIONBIO test */
302 #ifdef HAVE_SYS_TYPES_H
303 # include <sys/types.h>
308 #ifdef HAVE_SYS_SOCKET_H
309 # include <sys/socket.h>
311 #ifdef HAVE_SYS_IOCTL_H
312 # include <sys/ioctl.h>
314 #ifdef HAVE_STROPTS_H
315 # include <stropts.h>
323 if(0 != ioctl(0, FIONBIO, &flags))
330 #ifdef HAVE_IOCTL_SIOCGIFADDR
331 /* headers for FIONBIO test */
333 #ifdef HAVE_SYS_TYPES_H
334 # include <sys/types.h>
339 #ifdef HAVE_SYS_SOCKET_H
340 # include <sys/socket.h>
342 #ifdef HAVE_SYS_IOCTL_H
343 # include <sys/ioctl.h>
345 #ifdef HAVE_STROPTS_H
346 # include <stropts.h>
354 if(0 != ioctl(0, SIOCGIFADDR, &ifr))
361 #ifdef HAVE_SETSOCKOPT_SO_NONBLOCK
363 #ifdef HAVE_WINDOWS_H
364 # ifndef WIN32_LEAN_AND_MEAN
365 # define WIN32_LEAN_AND_MEAN
367 # include <windows.h>
368 # ifdef HAVE_WINSOCK2_H
369 # include <winsock2.h>
373 #ifdef HAVE_SYS_TYPES_H
374 # include <sys/types.h>
376 #ifdef HAVE_SYS_SOCKET_H
377 # include <sys/socket.h>
384 if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0))
390 #ifdef HAVE_GLIBC_STRERROR_R
394 void check(char c) {}
399 /* This will not compile if strerror_r does not return a char* */
400 check(strerror_r(EACCES, buffer, sizeof(buffer))[0]);
404 #ifdef HAVE_POSIX_STRERROR_R
408 /* float, because a pointer can't be implicitly cast to float */
409 void check(float f) {}
414 /* This will not compile if strerror_r does not return an int */
415 check(strerror_r(EACCES, buffer, sizeof(buffer)));
419 #ifdef HAVE_FSETXATTR_6
420 #include <sys/xattr.h> /* header from libc, not from libattr */
423 fsetxattr(0, 0, 0, 0, 0, 0);
427 #ifdef HAVE_FSETXATTR_5
428 #include <sys/xattr.h> /* header from libc, not from libattr */
431 fsetxattr(0, 0, 0, 0, 0);
435 #ifdef HAVE_CLOCK_GETTIME_MONOTONIC
439 struct timespec ts = {0, 0};
440 clock_gettime(CLOCK_MONOTONIC, &ts);
444 #ifdef HAVE_BUILTIN_AVAILABLE
447 if(__builtin_available(macOS 10.12, *)) {}
451 #ifdef HAVE_VARIADIC_MACROS_C99
452 #define c99_vmacro3(first, ...) fun3(first, __VA_ARGS__)
453 #define c99_vmacro2(first, ...) fun2(first, __VA_ARGS__)
455 int fun3(int arg1, int arg2, int arg3);
456 int fun2(int arg1, int arg2);
458 int fun3(int arg1, int arg2, int arg3) {
459 return arg1 + arg2 + arg3;
461 int fun2(int arg1, int arg2) {
467 int res3 = c99_vmacro3(1, 2, 3);
468 int res2 = c99_vmacro2(1, 2);
474 #ifdef HAVE_VARIADIC_MACROS_GCC
475 #define gcc_vmacro3(first, args...) fun3(first, args)
476 #define gcc_vmacro2(first, args...) fun2(first, args)
478 int fun3(int arg1, int arg2, int arg3);
479 int fun2(int arg1, int arg2);
481 int fun3(int arg1, int arg2, int arg3) {
482 return arg1 + arg2 + arg3;
484 int fun2(int arg1, int arg2) {
490 int res3 = gcc_vmacro3(1, 2, 3);
491 int res2 = gcc_vmacro2(1, 2);
499 #ifdef HAVE_SYS_TYPES_H
500 # include <sys/types.h>
505 #ifdef HAVE_STDATOMIC_H
506 # include <stdatomic.h>
513 i = 0; // Force an atomic-write operation.
517 #ifdef HAVE_WIN32_WINNT
520 # include "../lib/setup-win32.h"
524 #define enquote(x) #x
525 #define expand(x) enquote(x)
526 #pragma message("_WIN32_WINNT=" expand(_WIN32_WINNT))