CurlTests.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2014, 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.haxx.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. #include <sys/types.h>
  25. #include <sys/time.h>
  26. #include <time.h>
  27. int
  28. main ()
  29. {
  30. if ((struct tm *) 0)
  31. return 0;
  32. ;
  33. return 0;
  34. }
  35. #endif
  36. #ifdef HAVE_FCNTL_O_NONBLOCK
  37. /* headers for FCNTL_O_NONBLOCK test */
  38. #include <sys/types.h>
  39. #include <unistd.h>
  40. #include <fcntl.h>
  41. /* */
  42. #if defined(sun) || defined(__sun__) || \
  43. defined(__SUNPRO_C) || defined(__SUNPRO_CC)
  44. # if defined(__SVR4) || defined(__srv4__)
  45. # define PLATFORM_SOLARIS
  46. # else
  47. # define PLATFORM_SUNOS4
  48. # endif
  49. #endif
  50. #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
  51. # define PLATFORM_AIX_V3
  52. #endif
  53. /* */
  54. #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
  55. #error "O_NONBLOCK does not work on this platform"
  56. #endif
  57. int
  58. main ()
  59. {
  60. /* O_NONBLOCK source test */
  61. int flags = 0;
  62. if(0 != fcntl(0, F_SETFL, flags | O_NONBLOCK))
  63. return 1;
  64. return 0;
  65. }
  66. #endif
  67. /* tests for gethostbyaddr_r or gethostbyname_r */
  68. #if defined(HAVE_GETHOSTBYADDR_R_5_REENTRANT) || \
  69. defined(HAVE_GETHOSTBYADDR_R_7_REENTRANT) || \
  70. defined(HAVE_GETHOSTBYADDR_R_8_REENTRANT) || \
  71. defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT) || \
  72. defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) || \
  73. defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
  74. # define _REENTRANT
  75. /* no idea whether _REENTRANT is always set, just invent a new flag */
  76. # define TEST_GETHOSTBYFOO_REENTRANT
  77. #endif
  78. #if defined(HAVE_GETHOSTBYADDR_R_5) || \
  79. defined(HAVE_GETHOSTBYADDR_R_7) || \
  80. defined(HAVE_GETHOSTBYADDR_R_8) || \
  81. defined(HAVE_GETHOSTBYNAME_R_3) || \
  82. defined(HAVE_GETHOSTBYNAME_R_5) || \
  83. defined(HAVE_GETHOSTBYNAME_R_6) || \
  84. defined(TEST_GETHOSTBYFOO_REENTRANT)
  85. #include <sys/types.h>
  86. #include <netdb.h>
  87. int main(void)
  88. {
  89. char *address = "example.com";
  90. int length = 0;
  91. int type = 0;
  92. struct hostent h;
  93. int rc = 0;
  94. #if defined(HAVE_GETHOSTBYADDR_R_5) || \
  95. defined(HAVE_GETHOSTBYADDR_R_5_REENTRANT) || \
  96. \
  97. defined(HAVE_GETHOSTBYNAME_R_3) || \
  98. defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT)
  99. struct hostent_data hdata;
  100. #elif defined(HAVE_GETHOSTBYADDR_R_7) || \
  101. defined(HAVE_GETHOSTBYADDR_R_7_REENTRANT) || \
  102. defined(HAVE_GETHOSTBYADDR_R_8) || \
  103. defined(HAVE_GETHOSTBYADDR_R_8_REENTRANT) || \
  104. \
  105. defined(HAVE_GETHOSTBYNAME_R_5) || \
  106. defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT) || \
  107. defined(HAVE_GETHOSTBYNAME_R_6) || \
  108. defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
  109. char buffer[8192];
  110. int h_errnop;
  111. struct hostent *hp;
  112. #endif
  113. #ifndef gethostbyaddr_r
  114. (void)gethostbyaddr_r;
  115. #endif
  116. #if defined(HAVE_GETHOSTBYADDR_R_5) || \
  117. defined(HAVE_GETHOSTBYADDR_R_5_REENTRANT)
  118. rc = gethostbyaddr_r(address, length, type, &h, &hdata);
  119. #elif defined(HAVE_GETHOSTBYADDR_R_7) || \
  120. defined(HAVE_GETHOSTBYADDR_R_7_REENTRANT)
  121. hp = gethostbyaddr_r(address, length, type, &h, buffer, 8192, &h_errnop);
  122. (void)hp;
  123. #elif defined(HAVE_GETHOSTBYADDR_R_8) || \
  124. defined(HAVE_GETHOSTBYADDR_R_8_REENTRANT)
  125. rc = gethostbyaddr_r(address, length, type, &h, buffer, 8192, &hp, &h_errnop);
  126. #endif
  127. #if defined(HAVE_GETHOSTBYNAME_R_3) || \
  128. defined(HAVE_GETHOSTBYNAME_R_3_REENTRANT)
  129. rc = gethostbyname_r(address, &h, &hdata);
  130. #elif defined(HAVE_GETHOSTBYNAME_R_5) || \
  131. defined(HAVE_GETHOSTBYNAME_R_5_REENTRANT)
  132. rc = gethostbyname_r(address, &h, buffer, 8192, &h_errnop);
  133. (void)hp; /* not used for test */
  134. #elif defined(HAVE_GETHOSTBYNAME_R_6) || \
  135. defined(HAVE_GETHOSTBYNAME_R_6_REENTRANT)
  136. rc = gethostbyname_r(address, &h, buffer, 8192, &hp, &h_errnop);
  137. #endif
  138. (void)length;
  139. (void)type;
  140. (void)rc;
  141. return 0;
  142. }
  143. #endif
  144. #ifdef HAVE_SOCKLEN_T
  145. #ifdef _WIN32
  146. #include <ws2tcpip.h>
  147. #else
  148. #include <sys/types.h>
  149. #include <sys/socket.h>
  150. #endif
  151. int
  152. main ()
  153. {
  154. if ((socklen_t *) 0)
  155. return 0;
  156. if (sizeof (socklen_t))
  157. return 0;
  158. ;
  159. return 0;
  160. }
  161. #endif
  162. #ifdef HAVE_IN_ADDR_T
  163. #include <sys/types.h>
  164. #include <sys/socket.h>
  165. #include <arpa/inet.h>
  166. int
  167. main ()
  168. {
  169. if ((in_addr_t *) 0)
  170. return 0;
  171. if (sizeof (in_addr_t))
  172. return 0;
  173. ;
  174. return 0;
  175. }
  176. #endif
  177. #ifdef HAVE_BOOL_T
  178. #ifdef HAVE_SYS_TYPES_H
  179. #include <sys/types.h>
  180. #endif
  181. #ifdef HAVE_STDBOOL_H
  182. #include <stdbool.h>
  183. #endif
  184. int
  185. main ()
  186. {
  187. if (sizeof (bool *) )
  188. return 0;
  189. ;
  190. return 0;
  191. }
  192. #endif
  193. #ifdef STDC_HEADERS
  194. #include <stdlib.h>
  195. #include <stdarg.h>
  196. #include <string.h>
  197. #include <float.h>
  198. int main() { return 0; }
  199. #endif
  200. #ifdef RETSIGTYPE_TEST
  201. #include <sys/types.h>
  202. #include <signal.h>
  203. #ifdef signal
  204. # undef signal
  205. #endif
  206. #ifdef __cplusplus
  207. extern "C" void (*signal (int, void (*)(int)))(int);
  208. #else
  209. void (*signal ()) ();
  210. #endif
  211. int
  212. main ()
  213. {
  214. return 0;
  215. }
  216. #endif
  217. #ifdef HAVE_INET_NTOA_R_DECL
  218. #include <arpa/inet.h>
  219. typedef void (*func_type)();
  220. int main()
  221. {
  222. #ifndef inet_ntoa_r
  223. func_type func;
  224. func = (func_type)inet_ntoa_r;
  225. #endif
  226. return 0;
  227. }
  228. #endif
  229. #ifdef HAVE_INET_NTOA_R_DECL_REENTRANT
  230. #define _REENTRANT
  231. #include <arpa/inet.h>
  232. typedef void (*func_type)();
  233. int main()
  234. {
  235. #ifndef inet_ntoa_r
  236. func_type func;
  237. func = (func_type)&inet_ntoa_r;
  238. #endif
  239. return 0;
  240. }
  241. #endif
  242. #ifdef HAVE_GETADDRINFO
  243. #include <netdb.h>
  244. #include <sys/types.h>
  245. #include <sys/socket.h>
  246. int main(void) {
  247. struct addrinfo hints, *ai;
  248. int error;
  249. memset(&hints, 0, sizeof(hints));
  250. hints.ai_family = AF_UNSPEC;
  251. hints.ai_socktype = SOCK_STREAM;
  252. #ifndef getaddrinfo
  253. (void)getaddrinfo;
  254. #endif
  255. error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
  256. if (error) {
  257. return 1;
  258. }
  259. return 0;
  260. }
  261. #endif
  262. #ifdef HAVE_FILE_OFFSET_BITS
  263. #ifdef _FILE_OFFSET_BITS
  264. #undef _FILE_OFFSET_BITS
  265. #endif
  266. #define _FILE_OFFSET_BITS 64
  267. #include <sys/types.h>
  268. /* Check that off_t can represent 2**63 - 1 correctly.
  269. We can't simply define LARGE_OFF_T to be 9223372036854775807,
  270. since some C++ compilers masquerading as C compilers
  271. incorrectly reject 9223372036854775807. */
  272. #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
  273. int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
  274. && LARGE_OFF_T % 2147483647 == 1)
  275. ? 1 : -1];
  276. int main () { ; return 0; }
  277. #endif
  278. #ifdef HAVE_IOCTLSOCKET
  279. /* includes start */
  280. #ifdef HAVE_WINDOWS_H
  281. # ifndef WIN32_LEAN_AND_MEAN
  282. # define WIN32_LEAN_AND_MEAN
  283. # endif
  284. # include <windows.h>
  285. # ifdef HAVE_WINSOCK2_H
  286. # include <winsock2.h>
  287. # else
  288. # ifdef HAVE_WINSOCK_H
  289. # include <winsock.h>
  290. # endif
  291. # endif
  292. #endif
  293. int
  294. main ()
  295. {
  296. /* ioctlsocket source code */
  297. int socket;
  298. unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
  299. ;
  300. return 0;
  301. }
  302. #endif
  303. #ifdef HAVE_IOCTLSOCKET_CAMEL
  304. /* includes start */
  305. #ifdef HAVE_WINDOWS_H
  306. # ifndef WIN32_LEAN_AND_MEAN
  307. # define WIN32_LEAN_AND_MEAN
  308. # endif
  309. # include <windows.h>
  310. # ifdef HAVE_WINSOCK2_H
  311. # include <winsock2.h>
  312. # else
  313. # ifdef HAVE_WINSOCK_H
  314. # include <winsock.h>
  315. # endif
  316. # endif
  317. #endif
  318. int
  319. main ()
  320. {
  321. /* IoctlSocket source code */
  322. if(0 != IoctlSocket(0, 0, 0))
  323. return 1;
  324. ;
  325. return 0;
  326. }
  327. #endif
  328. #ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO
  329. /* includes start */
  330. #ifdef HAVE_WINDOWS_H
  331. # ifndef WIN32_LEAN_AND_MEAN
  332. # define WIN32_LEAN_AND_MEAN
  333. # endif
  334. # include <windows.h>
  335. # ifdef HAVE_WINSOCK2_H
  336. # include <winsock2.h>
  337. # else
  338. # ifdef HAVE_WINSOCK_H
  339. # include <winsock.h>
  340. # endif
  341. # endif
  342. #endif
  343. int
  344. main ()
  345. {
  346. /* IoctlSocket source code */
  347. long flags = 0;
  348. if(0 != ioctlsocket(0, FIONBIO, &flags))
  349. return 1;
  350. ;
  351. return 0;
  352. }
  353. #endif
  354. #ifdef HAVE_IOCTLSOCKET_FIONBIO
  355. /* includes start */
  356. #ifdef HAVE_WINDOWS_H
  357. # ifndef WIN32_LEAN_AND_MEAN
  358. # define WIN32_LEAN_AND_MEAN
  359. # endif
  360. # include <windows.h>
  361. # ifdef HAVE_WINSOCK2_H
  362. # include <winsock2.h>
  363. # else
  364. # ifdef HAVE_WINSOCK_H
  365. # include <winsock.h>
  366. # endif
  367. # endif
  368. #endif
  369. int
  370. main ()
  371. {
  372. int flags = 0;
  373. if(0 != ioctlsocket(0, FIONBIO, &flags))
  374. return 1;
  375. ;
  376. return 0;
  377. }
  378. #endif
  379. #ifdef HAVE_IOCTL_FIONBIO
  380. /* headers for FIONBIO test */
  381. /* includes start */
  382. #ifdef HAVE_SYS_TYPES_H
  383. # include <sys/types.h>
  384. #endif
  385. #ifdef HAVE_UNISTD_H
  386. # include <unistd.h>
  387. #endif
  388. #ifdef HAVE_SYS_SOCKET_H
  389. # include <sys/socket.h>
  390. #endif
  391. #ifdef HAVE_SYS_IOCTL_H
  392. # include <sys/ioctl.h>
  393. #endif
  394. #ifdef HAVE_STROPTS_H
  395. # include <stropts.h>
  396. #endif
  397. int
  398. main ()
  399. {
  400. int flags = 0;
  401. if(0 != ioctl(0, FIONBIO, &flags))
  402. return 1;
  403. ;
  404. return 0;
  405. }
  406. #endif
  407. #ifdef HAVE_IOCTL_SIOCGIFADDR
  408. /* headers for FIONBIO test */
  409. /* includes start */
  410. #ifdef HAVE_SYS_TYPES_H
  411. # include <sys/types.h>
  412. #endif
  413. #ifdef HAVE_UNISTD_H
  414. # include <unistd.h>
  415. #endif
  416. #ifdef HAVE_SYS_SOCKET_H
  417. # include <sys/socket.h>
  418. #endif
  419. #ifdef HAVE_SYS_IOCTL_H
  420. # include <sys/ioctl.h>
  421. #endif
  422. #ifdef HAVE_STROPTS_H
  423. # include <stropts.h>
  424. #endif
  425. #include <net/if.h>
  426. int
  427. main ()
  428. {
  429. struct ifreq ifr;
  430. if(0 != ioctl(0, SIOCGIFADDR, &ifr))
  431. return 1;
  432. ;
  433. return 0;
  434. }
  435. #endif
  436. #ifdef HAVE_SETSOCKOPT_SO_NONBLOCK
  437. /* includes start */
  438. #ifdef HAVE_WINDOWS_H
  439. # ifndef WIN32_LEAN_AND_MEAN
  440. # define WIN32_LEAN_AND_MEAN
  441. # endif
  442. # include <windows.h>
  443. # ifdef HAVE_WINSOCK2_H
  444. # include <winsock2.h>
  445. # else
  446. # ifdef HAVE_WINSOCK_H
  447. # include <winsock.h>
  448. # endif
  449. # endif
  450. #endif
  451. /* includes start */
  452. #ifdef HAVE_SYS_TYPES_H
  453. # include <sys/types.h>
  454. #endif
  455. #ifdef HAVE_SYS_SOCKET_H
  456. # include <sys/socket.h>
  457. #endif
  458. /* includes end */
  459. int
  460. main ()
  461. {
  462. if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0))
  463. return 1;
  464. ;
  465. return 0;
  466. }
  467. #endif
  468. #ifdef HAVE_GLIBC_STRERROR_R
  469. #include <string.h>
  470. #include <errno.h>
  471. int
  472. main () {
  473. char buffer[1024]; /* big enough to play with */
  474. char *string =
  475. strerror_r(EACCES, buffer, sizeof(buffer));
  476. /* this should've returned a string */
  477. if(!string || !string[0])
  478. return 99;
  479. return 0;
  480. }
  481. #endif
  482. #ifdef HAVE_POSIX_STRERROR_R
  483. #include <string.h>
  484. #include <errno.h>
  485. int
  486. main () {
  487. char buffer[1024]; /* big enough to play with */
  488. int error =
  489. strerror_r(EACCES, buffer, sizeof(buffer));
  490. /* This should've returned zero, and written an error string in the
  491. buffer.*/
  492. if(!buffer[0] || error)
  493. return 99;
  494. return 0;
  495. }
  496. #endif
  497. #ifdef HAVE_FSETXATTR_6
  498. #include <sys/xattr.h> /* header from libc, not from libattr */
  499. int
  500. main() {
  501. fsetxattr(0, 0, 0, 0, 0, 0);
  502. return 0;
  503. }
  504. #endif
  505. #ifdef HAVE_FSETXATTR_5
  506. #include <sys/xattr.h> /* header from libc, not from libattr */
  507. int
  508. main() {
  509. fsetxattr(0, 0, 0, 0, 0);
  510. return 0;
  511. }
  512. #endif