cURL / Mailing Lists / curl-library / Single Mail


return type of callback functions

From: <>
Date: Thu, 02 Apr 2009 06:15:27 +0000


I want to return -1 in my header and data callback function. I want this so
that I can download few bytes of data and terminate the
transfer instead of downloading entire URL content.

libcurl doc says "The callback function must return the number of bytes
actually taken care of, or return -1 to signal error to the library".

The signature of callback functions should be
size_t function( void *ptr, size_t size, size_t nmemb, void *stream)

size_t is unsigned int. So if I return -1 to libcurl, will it treat it as a
very large number?? (loss of sign) Or this case is handled by libcurl. Even
if I pass unsigned int (-1)
will it still work fine.??

I wanted help on this matter since when I run pc-lint on my code, It gives
me this warning about int to uint conversion.

I have done something like this

const size_t ABORT_TRANSFER = -1;

size_t ContentCallback(void* ptr, size_t size, size_t nmemb, void* userp)
uint bytesReceived = ABORT_TRANSFER;
if (0 != ptr)
bytesReceived = (size*nmemb);
buffer += std::string(static_cast<char*>(ptr), bytesReceived);

I want to know if its safe to do const size_t ABORT_TRANSFER = -1 here and
libcurl can handle this unsigned(-1) condition.

Thanks and regards
Received on 2009-04-02