CurlTests.c 8.4 KB

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