cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Error in ftpget.c example?

From: Juan Manuel Lopez Baio <jmbaio_at_gmail.com>
Date: Tue, 19 Sep 2006 12:04:32 -0300

On 9/19/06, Juan Manuel Lopez Baio <jmbaio_at_gmail.com> wrote:
> Hello.
> In the ftpget.c example that comes with the distribution, the function
> below is provided to write data to disk:
>
> int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
> {
> struct FtpFile *out=(struct FtpFile *)stream;
> if(out && !out->stream) {
> /* open file for writing */
> out->stream=fopen(out->filename, "wb");
> if(!out->stream)
> return -1; /* failure, can't open file to write */
> }
> return fwrite(buffer, size, nmemb, out->stream);
> }
>
> Shouldn't this function close the file stream, since it opens it, or
> does curl take care of that?

Sorry, my mistake; it's checked in main() and closed if necessary.
Aaaanyways, maybe it should be closed in the my_fwrite so it is solely
responsible for the file handling.
Received on 2006-09-19