Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl-7.19.0 / docs / examples / sepheaders.c
blob5fdc6e2368426ecd545895f06c6fcdf14c4c5fee
1 /*****************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: sepheaders.c,v 1.1.1.1 2008-09-23 16:32:05 hoffman Exp $
9 */
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <unistd.h>
15 #include <curl/curl.h>
16 #include <curl/types.h>
17 #include <curl/easy.h>
19 static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
21 int written = fwrite(ptr, size, nmemb, (FILE *)stream);
22 return written;
25 int main(int argc, char **argv)
27 CURL *curl_handle;
28 static const char *headerfilename = "head.out";
29 FILE *headerfile;
30 static const char *bodyfilename = "body.out";
31 FILE *bodyfile;
33 curl_global_init(CURL_GLOBAL_ALL);
35 /* init the curl session */
36 curl_handle = curl_easy_init();
38 /* set URL to get */
39 curl_easy_setopt(curl_handle, CURLOPT_URL, "http://curl.haxx.se");
41 /* no progress meter please */
42 curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
44 /* send all data to this function */
45 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
47 /* open the files */
48 headerfile = fopen(headerfilename,"w");
49 if (headerfile == NULL) {
50 curl_easy_cleanup(curl_handle);
51 return -1;
53 bodyfile = fopen(bodyfilename,"w");
54 if (bodyfile == NULL) {
55 curl_easy_cleanup(curl_handle);
56 return -1;
59 /* we want the headers to this file handle */
60 curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, headerfile);
63 * Notice here that if you want the actual data sent anywhere else but
64 * stdout, you should consider using the CURLOPT_WRITEDATA option. */
66 /* get it! */
67 curl_easy_perform(curl_handle);
69 /* close the header file */
70 fclose(headerfile);
72 /* cleanup curl stuff */
73 curl_easy_cleanup(curl_handle);
75 return 0;