CurlTests.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2011, 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 http://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. #ifdef HAVE_GETHOSTBYADDR_R_5
  68. #include <sys/types.h>
  69. #include <netdb.h>
  70. int
  71. main ()
  72. {
  73. char * address;
  74. int length;
  75. int type;
  76. struct hostent h;
  77. struct hostent_data hdata;
  78. int rc;
  79. #ifndef gethostbyaddr_r
  80. (void)gethostbyaddr_r;
  81. #endif
  82. rc = gethostbyaddr_r(address, length, type, &h, &hdata);
  83. ;
  84. return 0;
  85. }
  86. #endif
  87. #ifdef HAVE_GETHOSTBYADDR_R_5_REENTRANT
  88. #define _REENTRANT
  89. #include <sys/types.h>
  90. #include <netdb.h>
  91. int
  92. main ()
  93. {
  94. char * address;
  95. int length;q
  96. int type;
  97. struct hostent h;
  98. struct hostent_data hdata;
  99. int rc;
  100. #ifndef gethostbyaddr_r
  101. (void)gethostbyaddr_r;
  102. #endif
  103. rc = gethostbyaddr_r(address, length, type, &h, &hdata);
  104. ;
  105. return 0;
  106. }
  107. #endif
  108. #ifdef HAVE_GETHOSTBYADDR_R_7
  109. #include <sys/types.h>
  110. #include <netdb.h>
  111. int
  112. main ()
  113. {
  114. char * address;
  115. int length;
  116. int type;
  117. struct hostent h;
  118. char buffer[8192];
  119. int h_errnop;
  120. struct hostent * hp;
  121. #ifndef gethostbyaddr_r
  122. (void)gethostbyaddr_r;
  123. #endif
  124. hp = gethostbyaddr_r(address, length, type, &h,
  125. buffer, 8192, &h_errnop);
  126. ;
  127. return 0;
  128. }
  129. #endif
  130. #ifdef HAVE_GETHOSTBYADDR_R_7_REENTRANT
  131. #define _REENTRANT
  132. #include <sys/types.h>
  133. #include <netdb.h>
  134. int
  135. main ()
  136. {
  137. char * address;
  138. int length;
  139. int type;
  140. struct hostent h;
  141. char buffer[8192];
  142. int h_errnop;
  143. struct hostent * hp;
  144. #ifndef gethostbyaddr_r
  145. (void)gethostbyaddr_r;
  146. #endif
  147. hp = gethostbyaddr_r(address, length, type, &h,
  148. buffer, 8192, &h_errnop);
  149. ;
  150. return 0;
  151. }
  152. #endif
  153. #ifdef HAVE_GETHOSTBYADDR_R_8
  154. #include <sys/types.h>
  155. #include <netdb.h>
  156. int
  157. main ()
  158. {
  159. char * address;
  160. int length;
  161. int type;
  162. struct hostent h;
  163. char buffer[8192];
  164. int h_errnop;
  165. struct hostent * hp;
  166. int rc;
  167. #ifndef gethostbyaddr_r
  168. (void)gethostbyaddr_r;
  169. #endif
  170. rc = gethostbyaddr_r(address, length, type, &h,
  171. buffer, 8192, &hp, &h_errnop);
  172. ;
  173. return 0;
  174. }
  175. #endif
  176. #ifdef HAVE_GETHOSTBYADDR_R_8_REENTRANT
  177. #define _REENTRANT
  178. #include <sys/types.h>
  179. #include <netdb.h>
  180. int
  181. main ()
  182. {
  183. char * address;
  184. int length;
  185. int type;
  186. struct hostent h;
  187. char buffer[8192];
  188. int h_errnop;
  189. struct hostent * hp;
  190. int rc;
  191. #ifndef gethostbyaddr_r
  192. (void)gethostbyaddr_r;
  193. #endif
  194. rc = gethostbyaddr_r(address, length, type, &h,
  195. buffer, 8192, &hp, &h_errnop);
  196. ;
  197. return 0;
  198. }
  199. #endif
  200. #ifdef HAVE_GETHOSTBYNAME_R_3
  201. #include <string.h>
  202. #include <sys/types.h>
  203. #include <netdb.h>
  204. #undef NULL
  205. #define NULL (void *)0
  206. int
  207. main ()
  208. {
  209. struct hostent_data data;
  210. #ifndef gethostbyname_r
  211. (void)gethostbyname_r;
  212. #endif
  213. gethostbyname_r(NULL, NULL, NULL);
  214. ;
  215. return 0;
  216. }
  217. #endif
  218. #ifdef HAVE_GETHOSTBYNAME_R_3_REENTRANT
  219. #define _REENTRANT
  220. #include <string.h>
  221. #include <sys/types.h>
  222. #include <netdb.h>
  223. #undef NULL
  224. #define NULL (void *)0
  225. int
  226. main ()
  227. {
  228. struct hostent_data data;
  229. #ifndef gethostbyname_r
  230. (void)gethostbyname_r;
  231. #endif
  232. gethostbyname_r(NULL, NULL, NULL);
  233. ;
  234. return 0;
  235. }
  236. #endif
  237. #ifdef HAVE_GETHOSTBYNAME_R_5
  238. #include <sys/types.h>
  239. #include <netinet/in.h>
  240. #include <netdb.h>
  241. #undef NULL
  242. #define NULL (void *)0
  243. int
  244. main ()
  245. {
  246. #ifndef gethostbyname_r
  247. (void)gethostbyname_r;
  248. #endif
  249. gethostbyname_r(NULL, NULL, NULL, 0, NULL);
  250. ;
  251. return 0;
  252. }
  253. #endif
  254. #ifdef HAVE_GETHOSTBYNAME_R_5_REENTRANT
  255. #define _REENTRANT
  256. #include <sys/types.h>
  257. #include <netdb.h>
  258. #undef NULL
  259. #define NULL (void *)0
  260. int
  261. main ()
  262. {
  263. #ifndef gethostbyname_r
  264. (void)gethostbyname_r;
  265. #endif
  266. gethostbyname_r(NULL, NULL, NULL, 0, NULL);
  267. ;
  268. return 0;
  269. }
  270. #endif
  271. #ifdef HAVE_GETHOSTBYNAME_R_6
  272. #include <sys/types.h>
  273. #include <netdb.h>
  274. #undef NULL
  275. #define NULL (void *)0
  276. int
  277. main ()
  278. {
  279. #ifndef gethostbyname_r
  280. (void)gethostbyname_r;
  281. #endif
  282. gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);
  283. ;
  284. return 0;
  285. }
  286. #endif
  287. #ifdef HAVE_GETHOSTBYNAME_R_6_REENTRANT
  288. #define _REENTRANT
  289. #include <sys/types.h>
  290. #include <netdb.h>
  291. #undef NULL
  292. #define NULL (void *)0
  293. int
  294. main ()
  295. {
  296. #ifndef gethostbyname_r
  297. (void)gethostbyname_r;
  298. #endif
  299. gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);
  300. ;
  301. return 0;
  302. }
  303. #endif
  304. #ifdef HAVE_SOCKLEN_T
  305. #ifdef _WIN32
  306. #include <ws2tcpip.h>
  307. #else
  308. #include <sys/types.h>
  309. #include <sys/socket.h>
  310. #endif
  311. int
  312. main ()
  313. {
  314. if ((socklen_t *) 0)
  315. return 0;
  316. if (sizeof (socklen_t))
  317. return 0;
  318. ;
  319. return 0;
  320. }
  321. #endif
  322. #ifdef HAVE_IN_ADDR_T
  323. #include <sys/types.h>
  324. #include <sys/socket.h>
  325. #include <arpa/inet.h>
  326. int
  327. main ()
  328. {
  329. if ((in_addr_t *) 0)
  330. return 0;
  331. if (sizeof (in_addr_t))
  332. return 0;
  333. ;
  334. return 0;
  335. }
  336. #endif
  337. #ifdef HAVE_BOOL_T
  338. #ifdef HAVE_SYS_TYPES_H
  339. #include <sys/types.h>
  340. #endif
  341. #ifdef HAVE_STDBOOL_H
  342. #include <stdbool.h>
  343. #endif
  344. int
  345. main ()
  346. {
  347. if (sizeof (bool *) )
  348. return 0;
  349. ;
  350. return 0;
  351. }
  352. #endif
  353. #ifdef STDC_HEADERS
  354. #include <stdlib.h>
  355. #include <stdarg.h>
  356. #include <string.h>
  357. #include <float.h>
  358. int main() { return 0; }
  359. #endif
  360. #ifdef RETSIGTYPE_TEST
  361. #include <sys/types.h>
  362. #include <signal.h>
  363. #ifdef signal
  364. # undef signal
  365. #endif
  366. #ifdef __cplusplus
  367. extern "C" void (*signal (int, void (*)(int)))(int);
  368. #else
  369. void (*signal ()) ();
  370. #endif
  371. int
  372. main ()
  373. {
  374. return 0;
  375. }
  376. #endif
  377. #ifdef HAVE_INET_NTOA_R_DECL
  378. #include <arpa/inet.h>
  379. typedef void (*func_type)();
  380. int main()
  381. {
  382. #ifndef inet_ntoa_r
  383. func_type func;
  384. func = (func_type)inet_ntoa_r;
  385. #endif
  386. return 0;
  387. }
  388. #endif
  389. #ifdef HAVE_INET_NTOA_R_DECL_REENTRANT
  390. #define _REENTRANT
  391. #include <arpa/inet.h>
  392. typedef void (*func_type)();
  393. int main()
  394. {
  395. #ifndef inet_ntoa_r
  396. func_type func;
  397. func = (func_type)&inet_ntoa_r;
  398. #endif
  399. return 0;
  400. }
  401. #endif
  402. #ifdef HAVE_GETADDRINFO
  403. #include <netdb.h>
  404. #include <sys/types.h>
  405. #include <sys/socket.h>
  406. int main(void) {
  407. struct addrinfo hints, *ai;
  408. int error;
  409. memset(&hints, 0, sizeof(hints));
  410. hints.ai_family = AF_UNSPEC;
  411. hints.ai_socktype = SOCK_STREAM;
  412. #ifndef getaddrinfo
  413. (void)getaddrinfo;
  414. #endif
  415. error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
  416. if (error) {
  417. return 1;
  418. }
  419. return 0;
  420. }
  421. #endif
  422. #ifdef HAVE_FILE_OFFSET_BITS
  423. #ifdef _FILE_OFFSET_BITS
  424. #undef _FILE_OFFSET_BITS
  425. #endif
  426. #define _FILE_OFFSET_BITS 64
  427. #include <sys/types.h>
  428. /* Check that off_t can represent 2**63 - 1 correctly.
  429. We can't simply define LARGE_OFF_T to be 9223372036854775807,
  430. since some C++ compilers masquerading as C compilers
  431. incorrectly reject 9223372036854775807. */
  432. #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
  433. int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
  434. && LARGE_OFF_T % 2147483647 == 1)
  435. ? 1 : -1];
  436. int main () { ; return 0; }
  437. #endif
  438. #ifdef HAVE_IOCTLSOCKET
  439. /* includes start */
  440. #ifdef HAVE_WINDOWS_H
  441. # ifndef WIN32_LEAN_AND_MEAN
  442. # define WIN32_LEAN_AND_MEAN
  443. # endif
  444. # include <windows.h>
  445. # ifdef HAVE_WINSOCK2_H
  446. # include <winsock2.h>
  447. # else
  448. # ifdef HAVE_WINSOCK_H
  449. # include <winsock.h>
  450. # endif
  451. # endif
  452. #endif
  453. int
  454. main ()
  455. {
  456. /* ioctlsocket source code */
  457. int socket;
  458. unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);
  459. ;
  460. return 0;
  461. }
  462. #endif
  463. #ifdef HAVE_IOCTLSOCKET_CAMEL
  464. /* includes start */
  465. #ifdef HAVE_WINDOWS_H
  466. # ifndef WIN32_LEAN_AND_MEAN
  467. # define WIN32_LEAN_AND_MEAN
  468. # endif
  469. # include <windows.h>
  470. # ifdef HAVE_WINSOCK2_H
  471. # include <winsock2.h>
  472. # else
  473. # ifdef HAVE_WINSOCK_H
  474. # include <winsock.h>
  475. # endif
  476. # endif
  477. #endif
  478. int
  479. main ()
  480. {
  481. /* IoctlSocket source code */
  482. if(0 != IoctlSocket(0, 0, 0))
  483. return 1;
  484. ;
  485. return 0;
  486. }
  487. #endif
  488. #ifdef HAVE_IOCTLSOCKET_CAMEL_FIONBIO
  489. /* includes start */
  490. #ifdef HAVE_WINDOWS_H
  491. # ifndef WIN32_LEAN_AND_MEAN
  492. # define WIN32_LEAN_AND_MEAN
  493. # endif
  494. # include <windows.h>
  495. # ifdef HAVE_WINSOCK2_H
  496. # include <winsock2.h>
  497. # else
  498. # ifdef HAVE_WINSOCK_H
  499. # include <winsock.h>
  500. # endif
  501. # endif
  502. #endif
  503. int
  504. main ()
  505. {
  506. /* IoctlSocket source code */
  507. long flags = 0;
  508. if(0 != ioctlsocket(0, FIONBIO, &flags))
  509. return 1;
  510. ;
  511. return 0;
  512. }
  513. #endif
  514. #ifdef HAVE_IOCTLSOCKET_FIONBIO
  515. /* includes start */
  516. #ifdef HAVE_WINDOWS_H
  517. # ifndef WIN32_LEAN_AND_MEAN
  518. # define WIN32_LEAN_AND_MEAN
  519. # endif
  520. # include <windows.h>
  521. # ifdef HAVE_WINSOCK2_H
  522. # include <winsock2.h>
  523. # else
  524. # ifdef HAVE_WINSOCK_H
  525. # include <winsock.h>
  526. # endif
  527. # endif
  528. #endif
  529. int
  530. main ()
  531. {
  532. int flags = 0;
  533. if(0 != ioctlsocket(0, FIONBIO, &flags))
  534. return 1;
  535. ;
  536. return 0;
  537. }
  538. #endif
  539. #ifdef HAVE_IOCTL_FIONBIO
  540. /* headers for FIONBIO test */
  541. /* includes start */
  542. #ifdef HAVE_SYS_TYPES_H
  543. # include <sys/types.h>
  544. #endif
  545. #ifdef HAVE_UNISTD_H
  546. # include <unistd.h>
  547. #endif
  548. #ifdef HAVE_SYS_SOCKET_H
  549. # include <sys/socket.h>
  550. #endif
  551. #ifdef HAVE_SYS_IOCTL_H
  552. # include <sys/ioctl.h>
  553. #endif
  554. #ifdef HAVE_STROPTS_H
  555. # include <stropts.h>
  556. #endif
  557. int
  558. main ()
  559. {
  560. int flags = 0;
  561. if(0 != ioctl(0, FIONBIO, &flags))
  562. return 1;
  563. ;
  564. return 0;
  565. }
  566. #endif
  567. #ifdef HAVE_IOCTL_SIOCGIFADDR
  568. /* headers for FIONBIO test */
  569. /* includes start */
  570. #ifdef HAVE_SYS_TYPES_H
  571. # include <sys/types.h>
  572. #endif
  573. #ifdef HAVE_UNISTD_H
  574. # include <unistd.h>
  575. #endif
  576. #ifdef HAVE_SYS_SOCKET_H
  577. # include <sys/socket.h>
  578. #endif
  579. #ifdef HAVE_SYS_IOCTL_H
  580. # include <sys/ioctl.h>
  581. #endif
  582. #ifdef HAVE_STROPTS_H
  583. # include <stropts.h>
  584. #endif
  585. #include <net/if.h>
  586. int
  587. main ()
  588. {
  589. struct ifreq ifr;
  590. if(0 != ioctl(0, SIOCGIFADDR, &ifr))
  591. return 1;
  592. ;
  593. return 0;
  594. }
  595. #endif
  596. #ifdef HAVE_SETSOCKOPT_SO_NONBLOCK
  597. /* includes start */
  598. #ifdef HAVE_WINDOWS_H
  599. # ifndef WIN32_LEAN_AND_MEAN
  600. # define WIN32_LEAN_AND_MEAN
  601. # endif
  602. # include <windows.h>
  603. # ifdef HAVE_WINSOCK2_H
  604. # include <winsock2.h>
  605. # else
  606. # ifdef HAVE_WINSOCK_H
  607. # include <winsock.h>
  608. # endif
  609. # endif
  610. #endif
  611. /* includes start */
  612. #ifdef HAVE_SYS_TYPES_H
  613. # include <sys/types.h>
  614. #endif
  615. #ifdef HAVE_SYS_SOCKET_H
  616. # include <sys/socket.h>
  617. #endif
  618. /* includes end */
  619. int
  620. main ()
  621. {
  622. if(0 != setsockopt(0, SOL_SOCKET, SO_NONBLOCK, 0, 0))
  623. return 1;
  624. ;
  625. return 0;
  626. }
  627. #endif
  628. #ifdef HAVE_GLIBC_STRERROR_R
  629. #include <string.h>
  630. #include <errno.h>
  631. int
  632. main () {
  633. char buffer[1024]; /* big enough to play with */
  634. char *string =
  635. strerror_r(EACCES, buffer, sizeof(buffer));
  636. /* this should've returned a string */
  637. if(!string || !string[0])
  638. return 99;
  639. return 0;
  640. }
  641. #endif
  642. #ifdef HAVE_POSIX_STRERROR_R
  643. #include <string.h>
  644. #include <errno.h>
  645. int
  646. main () {
  647. char buffer[1024]; /* big enough to play with */
  648. int error =
  649. strerror_r(EACCES, buffer, sizeof(buffer));
  650. /* This should've returned zero, and written an error string in the
  651. buffer.*/
  652. if(!buffer[0] || error)
  653. return 99;
  654. return 0;
  655. }
  656. #endif