]> git.street.me.uk Git - andy/viking.git/commitdiff
Portability: provide our own curl WRITE function
authorMathieu Albinet <mathieu17@gmail.com>
Sun, 27 Apr 2008 08:35:40 +0000 (08:35 +0000)
committerMathieu Albinet <mathieu17@gmail.com>
Sun, 27 Apr 2008 08:35:40 +0000 (08:35 +0000)
Even if writing to FILE* is supported by libcurl by default,
it seems that it is non-portable (win32 DLL specific "bug").

Submitted by Mathieu Albinet

ChangeLog
src/curl_download.c

index a05abf0f032d148ac591f03ceeff49392cf717db..7fb3e7d0d7071cae6c2cbcd650b29dd758fecef0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-04-26:
+Mathieu Albinet <mathieu17@gmail.com>:
+       * Portability: provide our own curl WRITE function
+
 2008-04-22:
 Robert Norris <rw_norris@hotmail.com>:
        * Fix: Initalize tv_usec field.
index ed822e501758e78a0782357e7ea2e33349b72ac8..4b13b688710e0f1a70a8999e08504d5760a8467c 100644 (file)
 #include "file.h"
 #include "curl_download.h"
 
+/*
+ * Even if writing to FILE* is supported by libcurl by default,
+ * it seems that it is non-portable (win32 DLL specific).
+ *
+ * So, we provide our own trivial CURLOPT_WRITEFUNCTION.
+ */
+static size_t curl_write_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
+{
+  return fwrite(ptr, size, nmemb, stream);
+}
+
 static gchar *get_cookie_file(gboolean init)
 {
   static gchar *cookie_file = NULL;
@@ -58,6 +69,7 @@ static gchar *get_cookie_file(gboolean init)
     CURL *curl = curl_easy_init();
     curl_easy_setopt(curl, CURLOPT_URL, "http://maps.google.com/"); /* google.com sets "PREF" cookie */
     curl_easy_setopt ( curl, CURLOPT_FILE, out_file );
+    curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, curl_write_func);
     curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookie_file);
     res = curl_easy_perform(curl);
     if (res != CURLE_OK) {
@@ -92,6 +104,7 @@ int curl_download_uri ( const char *uri, FILE *f, DownloadOptions *options )
     {
       curl_easy_setopt ( curl, CURLOPT_URL, uri );
       curl_easy_setopt ( curl, CURLOPT_FILE, f );
+      curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, curl_write_func);
       if (options != NULL) {
         if(options->referer != NULL)
           curl_easy_setopt ( curl, CURLOPT_REFERER, options->referer);