cURL / Mailing Lists / curl-library / Single Mail


Re: Slight bug in the c/c++ API (or maybe just docs)

From: Ben Greear <>
Date: Sun, 09 Dec 2001 14:04:02 -0700

Returning zero should not be an error, though it should
signal end-of-file. I think any value > 0 should be valid,
and libcurl should try again. Zero should mean end-of-file (ie don't
ask for more, and we're all done), and < 0 is an error. If we
need to stay with size_t instead of ssize_t, then 0xFFFFFFFF (-1, signed)
could be used to signal an error. Or, since the user is writing the
method anyway, curl doesn't really need to know there is an error,
and we can just return 0 to tell libcurl to finish up, and handle
the error our own way...

Daniel Stenberg wrote:

> On Fri, 7 Dec 2001, Ben Greear wrote:
>>The CURLOPT_READFUNCTION documentation talks about returning a -1 on
>>error, but size_t is unsigned (at least on RH 7.2 Linux)
>>Maybe you want ssize_t arguments??
> The docs is not correct. Returning 0 will signal error. If fact, returning
> anything but the size given to the function through the input arguments will
> cause libcurl to abort the transfer.

Specifically, that last sentence is bad:

Suppose libcurl asks for 2048 bytes, and we have 3 left in the file.
We have to return 3, and libcurl should happily process it, and then
ask for more (maybe we're reading from a pipe/socket, and now there are
7 more bytes to send...


Ben Greear <>       <Ben_Greear AT>
President of Candela Technologies Inc
Received on 2001-12-09