cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Problem setting CURLOPT_WRITEDATA to NULL

From: Simon Elliott <simon_at_ctsn.co.uk>
Date: Sat, 24 Jul 2010 10:14:51 +0100

Dan

Thanks for your response. See below.

On Friday, July 23, 2010, 7:33:24 PM, you wrote:
> On Fri, Jul 23, 2010 at 02:48:00PM +0100, Simon Elliott wrote:
>> I get an error in curl_easy_perform() when I set the CURLOPT_WRITEDATA
>> option to NULL or zero on win32. I need to do this because I've previously
>> set it to data for a callback.
>>
>> In debug mode this gives an assertion failure in sendf.c. In release mode
>> it just crashes. The problem doesn't happen if I comment out the
>> CURLOPT_WRITEDATA call.

> Just where do you expect the data to go in that case? The default write
> callback function is fwrite, so if you set WRITEDATA to NULL, fwrite will
> attempt to write to a NULL file handle.

I assumed that setting the CURLOPT_NOBODY option to 1 would mean that
no fwrite would take place. This is implied by the docs for
CURLOPT_PREQUOTE, and there are some messages in the mailing list
which suggest that this is the case for FTP but not for SFTP.

I also assumed that setting WRITEDATA to NULL would cause libcurl to
revert to its internal file handle, but this isn't in the docs

Since this isn't the case, I've made a CURLOPT_WRITEFUNCTION callback
which just returns zero.

This is for a "does this file exist on the server" function so that my
app can avoid doing any work if it doesn't find a particular flag
file. Maybe I should be looking at another approach for "does this
file exist"?

> Note also this line in the documentation:
> If you're using libcurl as a win32 DLL, you MUST use the
> CURLOPT_WRITEFUNCTION if you set this option [CURLOPT_WRITEDATA]
> or you will experience crashes.

Yes. Fortunately I'm not using any DLLs in this app.

Thanks again

Simon

-- 
Simon Elliott     http://www.ctsn.co.uk
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2010-07-24