cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Get what WRITEFUNCTION will return ?

From: Dirk Manske <dm_at_nonitor.de>
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:

"CALLBACK OPTIONS / CURLOPT_WRITEFUNCTION:
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;
    if(len>144)
     return 0; /* curl will abort with CURLE_WRITE_ERROR */
    else
     return len; /* ok */
 }

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-02-26