fix compiler warning: implicit conversion shortens 64-bit value into a 32-bit value
[platform/upstream/curl.git] / tests / libtest / lib556.c
1 /*****************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * $Id$
9  */
10
11 #include "test.h"
12
13 #include "memdebug.h"
14
15 /* For Windows, mainly (may be moved in a config file?) */
16 #ifndef STDIN_FILENO
17   #define STDIN_FILENO 0
18 #endif
19 #ifndef STDOUT_FILENO
20   #define STDOUT_FILENO 1
21 #endif
22 #ifndef STDERR_FILENO
23   #define STDERR_FILENO 2
24 #endif
25
26 int test(char *URL)
27 {
28   CURLcode res;
29   CURL *curl;
30
31   if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
32     fprintf(stderr, "curl_global_init() failed\n");
33     return TEST_ERR_MAJOR_BAD;
34   }
35
36   if ((curl = curl_easy_init()) == NULL) {
37     fprintf(stderr, "curl_easy_init() failed\n");
38     curl_global_cleanup();
39     return TEST_ERR_MAJOR_BAD;
40   }
41
42   curl_easy_setopt(curl, CURLOPT_URL, URL);
43   curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
44
45   res = curl_easy_perform(curl);
46
47   if(!res) {
48     /* we are connected, now get a HTTP document the raw way */
49     const char *request = "GET /556 HTTP/1.2\r\n"
50       "Host: ninja\r\n\r\n";
51     size_t iolen;
52     char buf[1024];
53
54     res = curl_easy_send(curl, request, strlen(request), &iolen);
55
56     if(!res) {
57       /* we assume that sending always work */
58       size_t total=0;
59
60       do {
61         /* busy-read like crazy */
62         res = curl_easy_recv(curl, buf, 1024, &iolen);
63
64         if(iolen)
65           /* send received stuff to stdout */
66           write(STDOUT_FILENO, buf, iolen);
67         total += iolen;
68
69       } while(((res == CURLE_OK) || (res == CURLE_AGAIN)) && (total < 129));
70     }
71   }
72
73
74   curl_easy_cleanup(curl);
75   curl_global_cleanup();
76
77   return (int)res;
78 }
79