cURL / Mailing Lists / curl-library / Single Mail

curl-library

sepheaders.c example

From: Guenter <lists_at_gknw.net>
Date: Thu, 20 Jun 2013 17:47:29 +0200

Hi,
while porting some code to Lua and looking through our samples I came
over sepheaders.c; the code looks a bit strange to me - I wonder why a
body file is created and opended, but then not used at all? Instead
there's only a hint comment about what to use when we want to have the
output somewhere else than stdout ...

any objections to apply below patch?

--- sepheaders.c.orig 2012-12-11 23:32:22.000000000 +0100
+++ sepheaders.c 2013-06-20 17:34:53.454223316 +0200
@@ -59,18 +59,17 @@
      curl_easy_cleanup(curl_handle);
      return -1;
    }
- bodyfile = fopen(bodyfilename,"w");
+ bodyfile = fopen(bodyfilename,"wb");
    if (bodyfile == NULL) {
      curl_easy_cleanup(curl_handle);
      return -1;
    }

- /* we want the headers to this file handle */
+ /* we want the headers be written to this file handle */
    curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, headerfile);

- /*
- * Notice here that if you want the actual data sent anywhere else but
- * stdout, you should consider using the CURLOPT_WRITEDATA option. */
+ /* we want the body be written to this file handle instead of stdout */
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, bodyfile);

    /* get it! */
    curl_easy_perform(curl_handle);
@@ -78,6 +77,9 @@
    /* close the header file */
    fclose(headerfile);

+ /* close the body file */
+ fclose(bodyfile);
+
    /* cleanup curl stuff */
    curl_easy_cleanup(curl_handle);

Gün.

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-06-20