Fixed some more simple compile warnings in the examples.
[platform/upstream/curl.git] / docs / examples / sepheaders.c
1 /*****************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * $Id$
9  */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14
15 #include <curl/curl.h>
16 #include <curl/types.h>
17 #include <curl/easy.h>
18
19 static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
20 {
21   int written = fwrite(ptr, size, nmemb, (FILE *)stream);
22   return written;
23 }
24
25 int main(int argc, char **argv)
26 {
27   CURL *curl_handle;
28   static const char *headerfilename = "head.out";
29   FILE *headerfile;
30   static const char *bodyfilename = "body.out";
31   FILE *bodyfile;
32
33   curl_global_init(CURL_GLOBAL_ALL);
34
35   /* init the curl session */
36   curl_handle = curl_easy_init();
37
38   /* set URL to get */
39   curl_easy_setopt(curl_handle, CURLOPT_URL, "http://curl.haxx.se");
40
41   /* no progress meter please */
42   curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1);
43
44   /* send all data to this function  */
45   curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
46
47   /* open the files */
48   headerfile = fopen(headerfilename,"w");
49   if (headerfile == NULL) {
50     curl_easy_cleanup(curl_handle);
51     return -1;
52   }
53   bodyfile = fopen(bodyfilename,"w");
54   if (bodyfile == NULL) {
55     curl_easy_cleanup(curl_handle);
56     return -1;
57   }
58
59   /* we want the headers to this file handle */
60   curl_easy_setopt(curl_handle,   CURLOPT_WRITEHEADER ,headerfile);
61
62   /*
63    * Notice here that if you want the actual data sent anywhere else but
64    * stdout, you should consider using the CURLOPT_WRITEDATA option.  */
65
66   /* get it! */
67   curl_easy_perform(curl_handle);
68
69   /* close the header file */
70   fclose(headerfile);
71
72   /* cleanup curl stuff */
73   curl_easy_cleanup(curl_handle);
74
75   return 0;
76 }