cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: returning -1 to CURLOPT_WRITEFUNCTION

From: jonatan <jonatan_at_cyberdude.com>
Date: Mon, 15 Oct 2001 15:43:25 +0200

> > the docs say to return -1 to the function set with CURLOPT_WRITEFUNCTION
>> to signal error. but that function is defined as returning size_t, which
>> is unsigned. how are you supposed to return -1 when you can only return
>> an unsigned value?
>
>That is indeed a very good question! ;-)
>
> > maybe the return type of CURLOPT_WRITEFUNCTION should be ssize_t or
>> ptrdiff_t instead of size_t.
>
>Well, to avoid having to change the prototype I think I'll change the
>documentation!
>
>The return code doesn't really matter, as returning anything other than the
>actually passed in size will make libcurl return CURLE_WRITE_ERROR.

can i assume that the function will never be called with 0 bytes, so
that returning 0 instead of -1 will signal error?

    /* suppose i want to signal error */
    return 0;

otherwise i'd have to do something like:

    /* suppose i want to signal error */
    return ( realsize == 0 ) ? 1 : 0;
Received on 2001-10-15