doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
httpput.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * $Id: httpput.c,v 1.5 2004/01/05 22:29:30 bagder Exp $
9  */
10 
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <sys/stat.h>
14 
15 #include <curl/curl.h>
16 
17 /*
18  * This example shows a HTTP PUT operation. PUTs a file given as a command
19  * line argument to the URL also given on the command line.
20  *
21  * This example also uses its own read callback.
22  */
23 
24 size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
25 {
26  size_t retcode;
27 
28  /* in real-world cases, this would probably get this data differently
29  as this fread() stuff is exactly what the library already would do
30  by default internally */
31  retcode = fread(ptr, size, nmemb, stream);
32 
33  fprintf(stderr, "*** We read %d bytes from file\n", retcode);
34 
35  return retcode;
36 }
37 
38 int main(int argc, char **argv)
39 {
40  CURL *curl;
41  CURLcode res;
42  FILE *ftpfile;
43  FILE * hd_src ;
44  int hd ;
45  struct stat file_info;
46 
47  char *file;
48  char *url;
49 
50  if(argc < 3)
51  return 1;
52 
53  file= argv[1];
54  url = argv[2];
55 
56  /* get the file size of the local file */
57  hd = open(file, O_RDONLY) ;
58  fstat(hd, &file_info);
59  close(hd) ;
60 
61  /* get a FILE * of the same file, could also be made with
62  fdopen() from the previous descriptor, but hey this is just
63  an example! */
64  hd_src = fopen(file, "rb");
65 
66  /* In windows, this will init the winsock stuff */
68 
69  /* get a curl handle */
70  curl = curl_easy_init();
71  if(curl) {
72  /* we want to use our own read function */
73  curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
74 
75  /* enable uploading */
76  curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
77 
78  /* HTTP PUT please */
79  curl_easy_setopt(curl, CURLOPT_PUT, TRUE);
80 
81  /* specify target URL, and note that this URL should include a file
82  name, not only a directory */
83  curl_easy_setopt(curl,CURLOPT_URL, url);
84 
85  /* now specify which file to upload */
86  curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
87 
88  /* and give the size of the upload */
89  curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_info.st_size);
90 
91  /* Now run off and do what you've been told! */
92  res = curl_easy_perform(curl);
93 
94  /* always cleanup */
95  curl_easy_cleanup(curl);
96  }
97  fclose(hd_src); /* close the local file */
98 
100  return 0;
101 }
CURLcode curl_global_init(long flags)
Globally initializes cURL given a bitwise set of the different features to initialize.
Definition: easy.c:147
#define O_RDONLY
CURLcode curl_easy_perform(CURL *curl)
Definition: easy.c:260
CURLcode
Definition: curl.h:209
CURLcode curl_easy_setopt(CURL *curl, CURLoption option,...)
Definition: easy.c:217
void curl_global_cleanup(void)
Globally cleanup cURL, uses the value of "init_flags" to determine what needs to be cleaned up and ...
Definition: easy.c:174
int main(int argc, char **argv)
Definition: httpput.c:38
size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
Definition: httpput.c:24
size_t fread(void *, size_t, size_t, FILE *)
GLsizeiptr size
Definition: glext.h:3112
void CURL
Definition: types.h:25
GLuint res
Definition: glext.h:5385
#define TRUE
Definition: mprintf.c:69
#define CURL_GLOBAL_ALL
Definition: curl.h:1153
#define CURLOPT_READDATA
Definition: curl.h:806
void curl_easy_cleanup(CURL *curl)
Definition: easy.c:288
CURL * curl_easy_init(void)
Definition: easy.c:195