1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
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.
13 *
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.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ***************************************************************************/
22 #ifdef TIME_WITH_SYS_TIME
23 /* Time with sys/time test */
24
25 #include <sys/types.h>
26 #include <sys/time.h>
27 #include <time.h>
28
29 int
main()30 main ()
31 {
32 if ((struct tm *) 0)
33 return 0;
34 ;
35 return 0;
36 }
37
38 #endif
39
40 #ifdef HAVE_FCNTL_O_NONBLOCK
41
42 /* headers for FCNTL_O_NONBLOCK test */
43 #include <sys/types.h>
44 #include <unistd.h>
45 #include <fcntl.h>
46 /* */
47 #if defined(sun) || defined(__sun__) || \
48 defined(__SUNPRO_C) || defined(__SUNPRO_CC)
49 # if defined(__SVR4) || defined(__srv4__)
50 # define PLATFORM_SOLARIS
51 # else
52 # define PLATFORM_SUNOS4
53 # endif
54 #endif
55 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
56 # define PLATFORM_AIX_V3
57 #endif
58 /* */
59 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
60 #error "O_NONBLOCK does not work on this platform"
61 #endif
62
63 int
main()64 main ()
65 {
66 /* O_NONBLOCK source test */
67 int flags = 0;
68 if(0 != fcntl(0, F_SETFL, flags | O_NONBLOCK))
69 return 1;
70 return 0;
71 }
72 #endif
73
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)
78 # define _REENTRANT
79 /* no idea whether _REENTRANT is always set, just invent a new flag */
80 # define TEST_GETHOSTBYFOO_REENTRANT
81 #endif
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>
87 #include <netdb.h>
main(void)88 int main(void)
89 {
90 char *address = "example.com";
91 int length = 0;
92 int type = 0;
93 struct hostent h;
94 int rc = 0;
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)
102 char buffer[8192];
103 int h_errnop;
104 struct hostent *hp;
105 #endif
106
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);
117 #endif
118
119 (void)length;
120 (void)type;
121 (void)rc;
122 return 0;
123 }
124 #endif
125
126 #ifdef HAVE_SOCKLEN_T
127 #ifdef _WIN32
128 #include <ws2tcpip.h>
129 #else
130 #include <sys/types.h>
131 #include <sys/socket.h>
132 #endif
133 int
main()134 main ()
135 {
136 if ((socklen_t *) 0)
137 return 0;
138 if (sizeof (socklen_t))
139 return 0;
140 ;
141 return 0;
142 }
143 #endif
144 #ifdef HAVE_IN_ADDR_T
145 #include <sys/types.h>
146 #include <sys/socket.h>
147 #include <arpa/inet.h>
148
149 int
main()150 main ()
151 {
152 if ((in_addr_t *) 0)
153 return 0;
154 if (sizeof (in_addr_t))
155 return 0;
156 ;
157 return 0;
158 }
159 #endif
160
161 #ifdef HAVE_BOOL_T
162 #ifdef HAVE_SYS_TYPES_H
163 #include <sys/types.h>
164 #endif
165 #ifdef HAVE_STDBOOL_H
166 #include <stdbool.h>
167 #endif
168 int
main()169 main ()
170 {
171 if (sizeof (bool *) )
172 return 0;
173 ;
174 return 0;
175 }
176 #endif
177
178 #ifdef STDC_HEADERS
179 #include <stdlib.h>
180 #include <stdarg.h>
181 #include <string.h>
182 #include <float.h>
main()183 int main() { return 0; }
184 #endif
185 #ifdef HAVE_GETADDRINFO
186 #include <netdb.h>
187 #include <sys/types.h>
188 #include <sys/socket.h>
189
main(void)190 int main(void) {
191 struct addrinfo hints, *ai;
192 int error;
193
194 memset(&hints, 0, sizeof(hints));
195 hints.ai_family = AF_UNSPEC;
196 hints.ai_socktype = SOCK_STREAM;
197 #ifndef getaddrinfo
198 (void)getaddrinfo;
199 #endif
200 error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
201 if (error) {
202 return 1;
203 }
204 return 0;
205 }
206 #endif
207 #ifdef HAVE_FILE_OFFSET_BITS
208 #ifdef _FILE_OFFSET_BITS
209 #undef _FILE_OFFSET_BITS
210 #endif
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)
220 ? 1 : -1];
main()221 int main () { ; return 0; }
222 #endif
223 #ifdef HAVE_IOCTLSOCKET
224 /* includes start */
225 #ifdef HAVE_WINDOWS_H
226 # ifndef WIN32_LEAN_AND_MEAN
227 # define WIN32_LEAN_AND_MEAN
228 # endif
229 # include <windows.h>
230 # ifdef HAVE_WINSOCK2_H
231 # include <winsock2.h>
232 # else
233 # ifdef HAVE_WINSOCK_H
234 # include <winsock.h>
235 # endif
236 # endif
237 #endif
238
239 int
main()240 main ()
241 {
242
243 /* ioctlsocket source code */
244 int socket;
245 unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
246
247 ;
248 return 0;
249 }
250
251 #endif
252 #ifdef HAVE_IOCTLSOCKET_CAMEL
253 /* includes start */
254 #ifdef HAVE_WINDOWS_H
255 # ifndef WIN32_LEAN_AND_MEAN
256 # define WIN32_LEAN_AND_MEAN
257 # endif
258 # include <windows.h>
259 # ifdef HAVE_WINSOCK2_H
260 # include <winsock2.h>
261 # else
262 # ifdef HAVE_WINSOCK_H
263 # include <winsock.h>
264 # endif
265 # endif
266 #endif
267
268 int
main()269 main ()
270 {
271
272 /* IoctlSocket source code */
273 if(0 != IoctlSocket(0, 0, 0))
274 return 1;
275 ;
276 return 0;
277 }
278 #endif
279 #ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO
280 /* includes start */
281 #ifdef HAVE_WINDOWS_H
282 # ifndef WIN32_LEAN_AND_MEAN
283 # define WIN32_LEAN_AND_MEAN
284 # endif
285 # include <windows.h>
286 # ifdef HAVE_WINSOCK2_H
287 # include <winsock2.h>
288 # else
289 # ifdef HAVE_WINSOCK_H
290 # include <winsock.h>
291 # endif
292 # endif
293 #endif
294
295 int
main()296 main ()
297 {
298
299 /* IoctlSocket source code */
300 long flags = 0;
301 if(0 != IoctlSocket(0, FIONBIO, &flags))
302 return 1;
303 ;
304 return 0;
305 }
306 #endif
307 #ifdef HAVE_IOCTLSOCKET_FIONBIO
308 /* includes start */
309 #ifdef HAVE_WINDOWS_H
310 # ifndef WIN32_LEAN_AND_MEAN
311 # define WIN32_LEAN_AND_MEAN
312 # endif
313 # include <windows.h>
314 # ifdef HAVE_WINSOCK2_H
315 # include <winsock2.h>
316 # else
317 # ifdef HAVE_WINSOCK_H
318 # include <winsock.h>
319 # endif
320 # endif
321 #endif
322
323 int
main()324 main ()
325 {
326
327 int flags = 0;
328 if(0 != ioctlsocket(0, FIONBIO, &flags))
329 return 1;
330
331 ;
332 return 0;
333 }
334 #endif
335 #ifdef HAVE_IOCTL_FIONBIO
336 /* headers for FIONBIO test */
337 /* includes start */
338 #ifdef HAVE_SYS_TYPES_H
339 # include <sys/types.h>
340 #endif
341 #ifdef HAVE_UNISTD_H
342 # include <unistd.h>
343 #endif
344 #ifdef HAVE_SYS_SOCKET_H
345 # include <sys/socket.h>
346 #endif
347 #ifdef HAVE_SYS_IOCTL_H
348 # include <sys/ioctl.h>
349 #endif
350 #ifdef HAVE_STROPTS_H
351 # include <stropts.h>
352 #endif
353
354 int
main()355 main ()
356 {
357
358 int flags = 0;
359 if(0 != ioctl(0, FIONBIO, &flags))
360 return 1;
361
362 ;
363 return 0;
364 }
365 #endif
366 #ifdef HAVE_IOCTL_SIOCGIFADDR
367 /* headers for FIONBIO test */
368 /* includes start */
369 #ifdef HAVE_SYS_TYPES_H
370 # include <sys/types.h>
371 #endif
372 #ifdef HAVE_UNISTD_H
373 # include <unistd.h>
374 #endif
375 #ifdef HAVE_SYS_SOCKET_H
376 # include <sys/socket.h>
377 #endif
378 #ifdef HAVE_SYS_IOCTL_H
379 # include <sys/ioctl.h>
380 #endif
381 #ifdef HAVE_STROPTS_H
382 # include <stropts.h>
383 #endif
384 #include <net/if.h>
385
386 int
main()387 main ()
388 {
389 struct ifreq ifr;
390 if(0 != ioctl(0, SIOCGIFADDR, &ifr))
391 return 1;
392
393 ;
394 return 0;
395 }
396 #endif
397 #ifdef HAVE_SETSOCKOPT_SO_NONBLOCK
398 /* includes start */
399 #ifdef HAVE_WINDOWS_H
400 # ifndef WIN32_LEAN_AND_MEAN
401 # define WIN32_LEAN_AND_MEAN
402 # endif
403 # include <windows.h>
404 # ifdef HAVE_WINSOCK2_H
405 # include <winsock2.h>
406 # else
407 # ifdef HAVE_WINSOCK_H
408 # include <winsock.h>
409 # endif
410 # endif
411 #endif
412 /* includes start */
413 #ifdef HAVE_SYS_TYPES_H
414 # include <sys/types.h>
415 #endif
416 #ifdef HAVE_SYS_SOCKET_H
417 # include <sys/socket.h>
418 #endif
419 /* includes end */
420
421 int
main()422 main ()
423 {
424 if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0))
425 return 1;
426 ;
427 return 0;
428 }
429 #endif
430 #ifdef HAVE_GLIBC_STRERROR_R
431 #include <string.h>
432 #include <errno.h>
433
check(char c)434 void check(char c) {}
435
436 int
main()437 main () {
438 char buffer[1024];
439 /* This will not compile if strerror_r does not return a char* */
440 check(strerror_r(EACCES, buffer, sizeof(buffer))[0]);
441 return 0;
442 }
443 #endif
444 #ifdef HAVE_POSIX_STRERROR_R
445 #include <string.h>
446 #include <errno.h>
447
448 /* float, because a pointer can't be implicitly cast to float */
check(float f)449 void check(float f) {}
450
451 int
main()452 main () {
453 char buffer[1024];
454 /* This will not compile if strerror_r does not return an int */
455 check(strerror_r(EACCES, buffer, sizeof(buffer)));
456 return 0;
457 }
458 #endif
459 #ifdef HAVE_FSETXATTR_6
460 #include <sys/xattr.h> /* header from libc, not from libattr */
461 int
main()462 main() {
463 fsetxattr(0, 0, 0, 0, 0, 0);
464 return 0;
465 }
466 #endif
467 #ifdef HAVE_FSETXATTR_5
468 #include <sys/xattr.h> /* header from libc, not from libattr */
469 int
main()470 main() {
471 fsetxattr(0, 0, 0, 0, 0);
472 return 0;
473 }
474 #endif
475 #ifdef HAVE_CLOCK_GETTIME_MONOTONIC
476 #include <time.h>
477 int
main()478 main() {
479 struct timespec ts = {0, 0};
480 clock_gettime(CLOCK_MONOTONIC, &ts);
481 return 0;
482 }
483 #endif
484 #ifdef HAVE_BUILTIN_AVAILABLE
485 int
main()486 main() {
487 if(__builtin_available(macOS 10.12, *)) {}
488 return 0;
489 }
490 #endif
491 #ifdef HAVE_VARIADIC_MACROS_C99
492 #define c99_vmacro3(first, ...) fun3(first, __VA_ARGS__)
493 #define c99_vmacro2(first, ...) fun2(first, __VA_ARGS__)
494
495 int fun3(int arg1, int arg2, int arg3);
496 int fun2(int arg1, int arg2);
497
fun3(int arg1,int arg2,int arg3)498 int fun3(int arg1, int arg2, int arg3) {
499 return arg1 + arg2 + arg3;
500 }
fun2(int arg1,int arg2)501 int fun2(int arg1, int arg2) {
502 return arg1 + arg2;
503 }
504
505 int
main()506 main() {
507 int res3 = c99_vmacro3(1, 2, 3);
508 int res2 = c99_vmacro2(1, 2);
509 (void)res3;
510 (void)res2;
511 return 0;
512 }
513 #endif
514 #ifdef HAVE_VARIADIC_MACROS_GCC
515 #define gcc_vmacro3(first, args...) fun3(first, args)
516 #define gcc_vmacro2(first, args...) fun2(first, args)
517
518 int fun3(int arg1, int arg2, int arg3);
519 int fun2(int arg1, int arg2);
520
fun3(int arg1,int arg2,int arg3)521 int fun3(int arg1, int arg2, int arg3) {
522 return arg1 + arg2 + arg3;
523 }
fun2(int arg1,int arg2)524 int fun2(int arg1, int arg2) {
525 return arg1 + arg2;
526 }
527
528 int
main()529 main() {
530 int res3 = gcc_vmacro3(1, 2, 3);
531 int res2 = gcc_vmacro2(1, 2);
532 (void)res3;
533 (void)res2;
534 return 0;
535 }
536 #endif
537