• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 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 
25 #ifdef HAVE_FCNTL_O_NONBLOCK
26 /* headers for FCNTL_O_NONBLOCK test */
27 #include <sys/types.h>
28 #include <unistd.h>
29 #include <fcntl.h>
30 /* */
31 #if defined(sun) || defined(__sun__) || \
32     defined(__SUNPRO_C) || defined(__SUNPRO_CC)
33 # if defined(__SVR4) || defined(__srv4__)
34 #  define PLATFORM_SOLARIS
35 # else
36 #  define PLATFORM_SUNOS4
37 # endif
38 #endif
39 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
40 # define PLATFORM_AIX_V3
41 #endif
42 /* */
43 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3)
44 #error "O_NONBLOCK does not work on this platform"
45 #endif
46 
main(void)47 int main(void)
48 {
49   /* O_NONBLOCK source test */
50   int flags = 0;
51   if(0 != fcntl(0, F_SETFL, flags | O_NONBLOCK))
52     return 1;
53   return 0;
54 }
55 #endif
56 
57 /* tests for gethostbyname_r */
58 #if defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT) || \
59     defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) || \
60     defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
61 #   define _REENTRANT
62     /* no idea whether _REENTRANT is always set, just invent a new flag */
63 #   define TEST_GETHOSTBYFOO_REENTRANT
64 #endif
65 #if defined(HAVE_GETHOSTBYNAME_R_3) || \
66     defined(HAVE_GETHOSTBYNAME_R_5) || \
67     defined(HAVE_GETHOSTBYNAME_R_6) || \
68     defined(TEST_GETHOSTBYFOO_REENTRANT)
69 #include <sys/types.h>
70 #include <netdb.h>
main(void)71 int main(void)
72 {
73   char *address = "example.com";
74   int length = 0;
75   int type = 0;
76   struct hostent h;
77   int rc = 0;
78 #if defined(HAVE_GETHOSTBYNAME_R_3) || \
79     defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT)
80   struct hostent_data hdata;
81 #elif defined(HAVE_GETHOSTBYNAME_R_5) || \
82       defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) || \
83       defined(HAVE_GETHOSTBYNAME_R_6) || \
84       defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
85   char buffer[8192];
86   int h_errnop;
87   struct hostent *hp;
88 #endif
89 
90 #if   defined(HAVE_GETHOSTBYNAME_R_3) || \
91       defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT)
92   rc = gethostbyname_r(address, &h, &hdata);
93 #elif defined(HAVE_GETHOSTBYNAME_R_5) || \
94       defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT)
95   rc = gethostbyname_r(address, &h, buffer, 8192, &h_errnop);
96   (void)hp; /* not used for test */
97 #elif defined(HAVE_GETHOSTBYNAME_R_6) || \
98       defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
99   rc = gethostbyname_r(address, &h, buffer, 8192, &hp, &h_errnop);
100 #endif
101 
102   (void)length;
103   (void)type;
104   (void)rc;
105   return 0;
106 }
107 #endif
108 
109 #ifdef HAVE_IN_ADDR_T
110 #include <sys/types.h>
111 #include <sys/socket.h>
112 #include <arpa/inet.h>
main(void)113 int main(void)
114 {
115   if((in_addr_t *) 0)
116     return 0;
117   if(sizeof(in_addr_t))
118     return 0;
119   ;
120   return 0;
121 }
122 #endif
123 
124 #ifdef HAVE_BOOL_T
125 #ifdef HAVE_SYS_TYPES_H
126 #include <sys/types.h>
127 #endif
128 #ifdef HAVE_STDBOOL_H
129 #include <stdbool.h>
130 #endif
main(void)131 int main(void)
132 {
133   if(sizeof(bool *))
134     return 0;
135   ;
136   return 0;
137 }
138 #endif
139 
140 #ifdef STDC_HEADERS
141 #include <stdlib.h>
142 #include <stdarg.h>
143 #include <string.h>
144 #include <float.h>
main(void)145 int main(void) { return 0; }
146 #endif
147 
148 #ifdef HAVE_FILE_OFFSET_BITS
149 #undef _FILE_OFFSET_BITS
150 #define _FILE_OFFSET_BITS 64
151 #include <sys/types.h>
152 /* Check that off_t can represent 2**63 - 1 correctly.
153    We cannot simply define LARGE_OFF_T to be 9223372036854775807,
154    since some C++ compilers masquerading as C compilers
155    incorrectly reject 9223372036854775807. */
156 #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
157 int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
158                      && LARGE_OFF_T % 2147483647 == 1)
159                     ? 1 : -1];
main(void)160 int main(void) { return 0; }
161 #endif
162 
163 #ifdef HAVE_IOCTLSOCKET
164 #ifdef _WIN32
165 #  include <winsock2.h>
166 #endif
main(void)167 int main(void)
168 {
169   /* ioctlsocket source code */
170   int socket;
171   unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
172   ;
173   return 0;
174 }
175 
176 #endif
177 
178 #ifdef HAVE_IOCTLSOCKET_CAMEL
179 #include <proto/bsdsocket.h>
main(void)180 int main(void)
181 {
182   /* IoctlSocket source code */
183   if(0 != IoctlSocket(0, 0, 0))
184     return 1;
185   ;
186   return 0;
187 }
188 #endif
189 
190 #ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO
191 #include <proto/bsdsocket.h>
192 #ifdef HAVE_SYS_IOCTL_H
193 #  include <sys/ioctl.h>
194 #endif
main(void)195 int main(void)
196 {
197   /* IoctlSocket source code */
198   long flags = 0;
199   if(0 != IoctlSocket(0, FIONBIO, &flags))
200     return 1;
201   ;
202   return 0;
203 }
204 #endif
205 
206 #ifdef HAVE_IOCTLSOCKET_FIONBIO
207 #ifdef _WIN32
208 #  include <winsock2.h>
209 #endif
main(void)210 int main(void)
211 {
212   unsigned long flags = 0;
213   if(0 != ioctlsocket(0, FIONBIO, &flags))
214     return 1;
215   ;
216   return 0;
217 }
218 #endif
219 
220 #ifdef HAVE_IOCTL_FIONBIO
221 /* headers for FIONBIO test */
222 #ifdef HAVE_SYS_TYPES_H
223 #  include <sys/types.h>
224 #endif
225 #ifdef HAVE_UNISTD_H
226 #  include <unistd.h>
227 #endif
228 #ifdef HAVE_SYS_SOCKET_H
229 #  include <sys/socket.h>
230 #endif
231 #ifdef HAVE_SYS_IOCTL_H
232 #  include <sys/ioctl.h>
233 #endif
234 #ifdef HAVE_STROPTS_H
235 #  include <stropts.h>
236 #endif
main(void)237 int main(void)
238 {
239   int flags = 0;
240   if(0 != ioctl(0, FIONBIO, &flags))
241     return 1;
242   ;
243   return 0;
244 }
245 #endif
246 
247 #ifdef HAVE_IOCTL_SIOCGIFADDR
248 /* headers for FIONBIO test */
249 #ifdef HAVE_SYS_TYPES_H
250 #  include <sys/types.h>
251 #endif
252 #ifdef HAVE_UNISTD_H
253 #  include <unistd.h>
254 #endif
255 #ifdef HAVE_SYS_SOCKET_H
256 #  include <sys/socket.h>
257 #endif
258 #ifdef HAVE_SYS_IOCTL_H
259 #  include <sys/ioctl.h>
260 #endif
261 #ifdef HAVE_STROPTS_H
262 #  include <stropts.h>
263 #endif
264 #include <net/if.h>
main(void)265 int main(void)
266 {
267   struct ifreq ifr;
268   if(0 != ioctl(0, SIOCGIFADDR, &ifr))
269     return 1;
270   ;
271   return 0;
272 }
273 #endif
274 
275 #ifdef HAVE_SETSOCKOPT_SO_NONBLOCK
276 #ifdef _WIN32
277 #  include <winsock2.h>
278 #endif
279 #ifdef HAVE_SYS_TYPES_H
280 #  include <sys/types.h>
281 #endif
282 #ifdef HAVE_SYS_SOCKET_H
283 #  include <sys/socket.h>
284 #endif
main(void)285 int main(void)
286 {
287   if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0))
288     return 1;
289   ;
290   return 0;
291 }
292 #endif
293 
294 #ifdef HAVE_GLIBC_STRERROR_R
295 #include <string.h>
296 #include <errno.h>
297 
check(char c)298 void check(char c) {}
299 
main(void)300 int main(void)
301 {
302   char buffer[1024];
303   /* This will not compile if strerror_r does not return a char* */
304   check(strerror_r(EACCES, buffer, sizeof(buffer))[0]);
305   return 0;
306 }
307 #endif
308 
309 #ifdef HAVE_POSIX_STRERROR_R
310 #include <string.h>
311 #include <errno.h>
312 
313 /* Float, because a pointer cannot be implicitly cast to float */
check(float f)314 void check(float f) {}
315 
main(void)316 int main(void)
317 {
318   char buffer[1024];
319   /* This will not compile if strerror_r does not return an int */
320   check(strerror_r(EACCES, buffer, sizeof(buffer)));
321   return 0;
322 }
323 #endif
324 
325 #ifdef HAVE_FSETXATTR_6
326 #include <sys/xattr.h> /* header from libc, not from libattr */
main(void)327 int main(void)
328 {
329   fsetxattr(0, 0, 0, 0, 0, 0);
330   return 0;
331 }
332 #endif
333 
334 #ifdef HAVE_FSETXATTR_5
335 #include <sys/xattr.h> /* header from libc, not from libattr */
main(void)336 int main(void)
337 {
338   fsetxattr(0, 0, 0, 0, 0);
339   return 0;
340 }
341 #endif
342 
343 #ifdef HAVE_CLOCK_GETTIME_MONOTONIC
344 #include <time.h>
main(void)345 int main(void)
346 {
347   struct timespec ts = {0, 0};
348   clock_gettime(CLOCK_MONOTONIC, &ts);
349   return 0;
350 }
351 #endif
352 
353 #ifdef HAVE_BUILTIN_AVAILABLE
main(void)354 int main(void)
355 {
356   if(__builtin_available(macOS 10.12, iOS 5.0, *)) {}
357   return 0;
358 }
359 #endif
360 
361 #ifdef HAVE_ATOMIC
362 #ifdef HAVE_SYS_TYPES_H
363 #  include <sys/types.h>
364 #endif
365 #ifdef HAVE_UNISTD_H
366 #  include <unistd.h>
367 #endif
368 #ifdef HAVE_STDATOMIC_H
369 #  include <stdatomic.h>
370 #endif
main(void)371 int main(void)
372 {
373   _Atomic int i = 1;
374   i = 0;  /* Force an atomic-write operation. */
375   return i;
376 }
377 #endif
378 
379 #ifdef HAVE_WIN32_WINNT
380 #ifdef _WIN32
381 #  ifndef NOGDI
382 #  define NOGDI
383 #  endif
384 #  include <windows.h>
385 #endif
386 
387 #define enquote(x) #x
388 #define expand(x) enquote(x)
389 #pragma message("_WIN32_WINNT=" expand(_WIN32_WINNT))
390 
main(void)391 int main(void)
392 {
393   return 0;
394 }
395 #endif
396 
397 #ifdef MINGW64_VERSION
398 #ifdef __MINGW32__
399 #  include <_mingw.h>
400 #endif
401 
402 #define enquote(x) #x
403 #define expand(x) enquote(x)
404 #pragma message("MINGW64_VERSION=" \
405   expand(__MINGW64_VERSION_MAJOR) "." \
406   expand(__MINGW64_VERSION_MINOR))
407 
main(void)408 int main(void)
409 {
410   return 0;
411 }
412 #endif
413