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 ***************************************************************************/
22 #ifdef TIME_WITH_SYS_TIME
23 /* Time with sys/time test */
25 #include <sys/types.h>
40 #ifdef HAVE_FCNTL_O_NONBLOCK
42 /* headers for FCNTL_O_NONBLOCK test */
43 #include <sys/types.h>
47 #if defined(sun) || defined(__sun__) || \
48 defined(__SUNPRO_C) || defined(__SUNPRO_CC)
49 # if defined(__SVR4) || defined(__srv4__)
50 # define PLATFORM_SOLARIS
52 # define PLATFORM_SUNOS4
55 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
56 # define PLATFORM_AIX_V3
59 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3)
60 #error "O_NONBLOCK does not work on this platform"
66 /* O_NONBLOCK source test */
68 if(0 != fcntl(0, F_SETFL, flags | O_NONBLOCK))
74 /* tests for gethostbyname_r */
75 #if defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT) || \
76 defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) || \
77 defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
79 /* no idea whether _REENTRANT is always set, just invent a new flag */
80 # define TEST_GETHOSTBYFOO_REENTRANT
82 #if defined(HAVE_GETHOSTBYNAME_R_3) || \
83 defined(HAVE_GETHOSTBYNAME_R_5) || \
84 defined(HAVE_GETHOSTBYNAME_R_6) || \
85 defined(TEST_GETHOSTBYFOO_REENTRANT)
86 #include <sys/types.h>
90 char *address = "example.com";
95 #if defined(HAVE_GETHOSTBYNAME_R_3) || \
96 defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT)
97 struct hostent_data hdata;
98 #elif defined(HAVE_GETHOSTBYNAME_R_5) || \
99 defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) || \
100 defined(HAVE_GETHOSTBYNAME_R_6) || \
101 defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
107 #if defined(HAVE_GETHOSTBYNAME_R_3) || \
108 defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT)
109 rc = gethostbyname_r(address, &h, &hdata);
110 #elif defined(HAVE_GETHOSTBYNAME_R_5) || \
111 defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT)
112 rc = gethostbyname_r(address, &h, buffer, 8192, &h_errnop);
113 (void)hp; /* not used for test */
114 #elif defined(HAVE_GETHOSTBYNAME_R_6) || \
115 defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
116 rc = gethostbyname_r(address, &h, buffer, 8192, &hp, &h_errnop);
126 #ifdef HAVE_SOCKLEN_T
128 #include <ws2tcpip.h>
130 #include <sys/types.h>
131 #include <sys/socket.h>
138 if (sizeof (socklen_t))
144 #ifdef HAVE_IN_ADDR_T
145 #include <sys/types.h>
146 #include <sys/socket.h>
147 #include <arpa/inet.h>
154 if (sizeof (in_addr_t))
162 #ifdef HAVE_SYS_TYPES_H
163 #include <sys/types.h>
165 #ifdef HAVE_STDBOOL_H
171 if (sizeof (bool *) )
183 int main() { return 0; }
185 #ifdef HAVE_GETADDRINFO
187 #include <sys/types.h>
188 #include <sys/socket.h>
191 struct addrinfo hints, *ai;
194 memset(&hints, 0, sizeof(hints));
195 hints.ai_family = AF_UNSPEC;
196 hints.ai_socktype = SOCK_STREAM;
200 error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
207 #ifdef HAVE_FILE_OFFSET_BITS
208 #ifdef _FILE_OFFSET_BITS
209 #undef _FILE_OFFSET_BITS
211 #define _FILE_OFFSET_BITS 64
212 #include <sys/types.h>
213 /* Check that off_t can represent 2**63 - 1 correctly.
214 We can't simply define LARGE_OFF_T to be 9223372036854775807,
215 since some C++ compilers masquerading as C compilers
216 incorrectly reject 9223372036854775807. */
217 #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
218 int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
219 && LARGE_OFF_T % 2147483647 == 1)
221 int main () { ; return 0; }
223 #ifdef HAVE_IOCTLSOCKET
225 #ifdef HAVE_WINDOWS_H
226 # ifndef WIN32_LEAN_AND_MEAN
227 # define WIN32_LEAN_AND_MEAN
229 # include <windows.h>
230 # ifdef HAVE_WINSOCK2_H
231 # include <winsock2.h>
239 /* ioctlsocket source code */
241 unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
248 #ifdef HAVE_IOCTLSOCKET_CAMEL
250 #ifdef HAVE_WINDOWS_H
251 # ifndef WIN32_LEAN_AND_MEAN
252 # define WIN32_LEAN_AND_MEAN
254 # include <windows.h>
255 # ifdef HAVE_WINSOCK2_H
256 # include <winsock2.h>
264 /* IoctlSocket source code */
265 if(0 != IoctlSocket(0, 0, 0))
271 #ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO
273 #ifdef HAVE_WINDOWS_H
274 # ifndef WIN32_LEAN_AND_MEAN
275 # define WIN32_LEAN_AND_MEAN
277 # include <windows.h>
278 # ifdef HAVE_WINSOCK2_H
279 # include <winsock2.h>
287 /* IoctlSocket source code */
289 if(0 != IoctlSocket(0, FIONBIO, &flags))
295 #ifdef HAVE_IOCTLSOCKET_FIONBIO
297 #ifdef HAVE_WINDOWS_H
298 # ifndef WIN32_LEAN_AND_MEAN
299 # define WIN32_LEAN_AND_MEAN
301 # include <windows.h>
302 # ifdef HAVE_WINSOCK2_H
303 # include <winsock2.h>
312 if(0 != ioctlsocket(0, FIONBIO, &flags))
319 #ifdef HAVE_IOCTL_FIONBIO
320 /* headers for FIONBIO test */
322 #ifdef HAVE_SYS_TYPES_H
323 # include <sys/types.h>
328 #ifdef HAVE_SYS_SOCKET_H
329 # include <sys/socket.h>
331 #ifdef HAVE_SYS_IOCTL_H
332 # include <sys/ioctl.h>
334 #ifdef HAVE_STROPTS_H
335 # include <stropts.h>
343 if(0 != ioctl(0, FIONBIO, &flags))
350 #ifdef HAVE_IOCTL_SIOCGIFADDR
351 /* headers for FIONBIO test */
353 #ifdef HAVE_SYS_TYPES_H
354 # include <sys/types.h>
359 #ifdef HAVE_SYS_SOCKET_H
360 # include <sys/socket.h>
362 #ifdef HAVE_SYS_IOCTL_H
363 # include <sys/ioctl.h>
365 #ifdef HAVE_STROPTS_H
366 # include <stropts.h>
374 if(0 != ioctl(0, SIOCGIFADDR, &ifr))
381 #ifdef HAVE_SETSOCKOPT_SO_NONBLOCK
383 #ifdef HAVE_WINDOWS_H
384 # ifndef WIN32_LEAN_AND_MEAN
385 # define WIN32_LEAN_AND_MEAN
387 # include <windows.h>
388 # ifdef HAVE_WINSOCK2_H
389 # include <winsock2.h>
393 #ifdef HAVE_SYS_TYPES_H
394 # include <sys/types.h>
396 #ifdef HAVE_SYS_SOCKET_H
397 # include <sys/socket.h>
404 if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0))
410 #ifdef HAVE_GLIBC_STRERROR_R
414 void check(char c) {}
419 /* This will not compile if strerror_r does not return a char* */
420 check(strerror_r(EACCES, buffer, sizeof(buffer))[0]);
424 #ifdef HAVE_POSIX_STRERROR_R
428 /* float, because a pointer can't be implicitly cast to float */
429 void check(float f) {}
434 /* This will not compile if strerror_r does not return an int */
435 check(strerror_r(EACCES, buffer, sizeof(buffer)));
439 #ifdef HAVE_FSETXATTR_6
440 #include <sys/xattr.h> /* header from libc, not from libattr */
443 fsetxattr(0, 0, 0, 0, 0, 0);
447 #ifdef HAVE_FSETXATTR_5
448 #include <sys/xattr.h> /* header from libc, not from libattr */
451 fsetxattr(0, 0, 0, 0, 0);
455 #ifdef HAVE_CLOCK_GETTIME_MONOTONIC
459 struct timespec ts = {0, 0};
460 clock_gettime(CLOCK_MONOTONIC, &ts);
464 #ifdef HAVE_BUILTIN_AVAILABLE
467 if(__builtin_available(macOS 10.12, *)) {}
471 #ifdef HAVE_VARIADIC_MACROS_C99
472 #define c99_vmacro3(first, ...) fun3(first, __VA_ARGS__)
473 #define c99_vmacro2(first, ...) fun2(first, __VA_ARGS__)
475 int fun3(int arg1, int arg2, int arg3);
476 int fun2(int arg1, int arg2);
478 int fun3(int arg1, int arg2, int arg3) {
479 return arg1 + arg2 + arg3;
481 int fun2(int arg1, int arg2) {
487 int res3 = c99_vmacro3(1, 2, 3);
488 int res2 = c99_vmacro2(1, 2);
494 #ifdef HAVE_VARIADIC_MACROS_GCC
495 #define gcc_vmacro3(first, args...) fun3(first, args)
496 #define gcc_vmacro2(first, args...) fun2(first, args)
498 int fun3(int arg1, int arg2, int arg3);
499 int fun2(int arg1, int arg2);
501 int fun3(int arg1, int arg2, int arg3) {
502 return arg1 + arg2 + arg3;
504 int fun2(int arg1, int arg2) {
510 int res3 = gcc_vmacro3(1, 2, 3);
511 int res2 = gcc_vmacro2(1, 2);