CurlTests.c 8.8 KB

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