cURL / Mailing Lists / curl-library / Single Mail


Re: Get what WRITEFUNCTION will return ?

From: Dirk Manske <>
Date: Sat, 26 Feb 2011 16:14:10 +0100

On Saturday 26 February 2011 15:49:02 Iskander Ben mahmoud wrote:
> There is any way to get what WriteFunction will return ?
Please read the docs again:

Function pointer that should match the following prototype: size_t function( void *ptr, size_t size, size_t nmemb, void *userdata); This function gets called by libcurl as soon as there is data received that needs to be saved. The size of the data pointed to by ptr is size multiplied with nmemb, it will not be zero terminated. Return the number of bytes actually taken care of. If that amount differs from the amount passed to your function, it'll signal an error to the library. This will abort the transfer and return CURLE_WRITE_ERROR.

You shouldn't use strlen.

> size_t verif_function(void *ptr, size_t size, size_t nmemb, void *userdata)
> {
> if(strlen(ptr)>144)
> return 0;
> else
> return 1;
> }

Rewrite this to:

size_t verif_function(void *ptr, size_t size, size_t nmemb, void *userdata)
    size_t len = size * nmemb;
     return 0; /* curl will abort with CURLE_WRITE_ERROR */
     return len; /* ok */

List admin:
Received on 2011-02-26