curl-library
Re: Doesn't fwrite() return the number of objects written, not the number of bytes?
Date: Fri, 31 Jul 2009 09:31:57 +0200 (CEST)
On Wed, 29 Jul 2009, Петър Иванов wrote:
> I was just writing a simple FTP-based application that needs to download
> files from an FTP server. I am passing a FILE pointer to my
> CURLOPT_WRITEFUNCTION. I return (size * fwrite(buffer, size, nmemb, stream)
> ). I do this because 'man fwrite' says that fwrite() returns nmemb in case
> successful. Is this correct? Does the write callback really needs to return
> the number of bytes processed? It may overflow, as the return value is also
> size_t. The FTP example here:
> http://curl.haxx.se/lxr/source/docs/examples/ftpget.c returns fwrite() only.
> Or maybe I am missing something?
Well... :-)
You're right in principle but as libcurl will ALWAYS pass in size as '1' the
sum of 'size * nmemb' is in fact the number of bytes...
Someone worked on getting the examples updated to better reflect this in the
past, but I lost the patch and I'm not convinced it is very important to make
the examples more complicated to communicate that point properly.
-- / daniel.haxx.seReceived on 2009-07-31