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