doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sepheaders.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * $Id: sepheaders.c,v 1.6 2003/11/19 08:21:34 bagder Exp $
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 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  char *headerfilename = "head.out";
29  FILE *headerfile;
30  char *bodyfilename = "body.out";
31  FILE *bodyfile;
32 
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  /* shut up completely */
45  curl_easy_setopt(curl_handle, CURLOPT_MUTE, 1);
46 
47  /* send all data to this function */
48  curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
49 
50  /* open the files */
51  headerfile = fopen(headerfilename,"w");
52  if (headerfile == NULL) {
53  curl_easy_cleanup(curl_handle);
54  return -1;
55  }
56  bodyfile = fopen(bodyfilename,"w");
57  if (bodyfile == NULL) {
58  curl_easy_cleanup(curl_handle);
59  return -1;
60  }
61 
62  /* we want the headers to this file handle */
63  curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER ,headerfile);
64 
65  /*
66  * Notice here that if you want the actual data sent anywhere else but
67  * stdout, you should consider using the CURLOPT_WRITEDATA option. */
68 
69  /* get it! */
70  curl_easy_perform(curl_handle);
71 
72  /* close the header file */
73  fclose(headerfile);
74 
75  /* cleanup curl stuff */
76  curl_easy_cleanup(curl_handle);
77 
78  return 0;
79 }
CURLcode curl_global_init(long flags)
Globally initializes cURL given a bitwise set of the different features to initialize.
Definition: easy.c:147
int main(int argc, char **argv)
Definition: sepheaders.c:25
CURLcode curl_easy_perform(CURL *curl)
Definition: easy.c:260
size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
Definition: sepheaders.c:19
CURLcode curl_easy_setopt(CURL *curl, CURLoption option,...)
Definition: easy.c:217
#define NULL
Definition: Lib.h:88
#define CURLOPT_MUTE
Definition: curl.h:813
GLsizeiptr size
Definition: glext.h:3112
void CURL
Definition: types.h:25
#define CURL_GLOBAL_ALL
Definition: curl.h:1153
void curl_easy_cleanup(CURL *curl)
Definition: easy.c:288
size_t fwrite(const void *, size_t, size_t, FILE *)
CURL * curl_easy_init(void)
Definition: easy.c:195