curl-library
Re: Problems with Http download under windows
Date: Mon, 30 Jun 2008 21:06:43 +0200
Maybe Libcurl will guarantee that this works across all platforms, and not
just linux.
But when I do this on windows it just crashes :
FILE * fp = fopen(out_file, "wb"); // also with option "w" it crashes
curl_easy_setopt(session, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(session, CURLOPT_WRITEFUNCTION, NULL);
curl_easy_perform(session);
fclose(fp);
So maybe my way, will maybe confuse future maintainers of your code...
But it is the only way that doesn't crashes.
Thanks for comments.
Cheers,
Loic
2008/6/30, Gary Maxwell <gmaxwell_at_casabi.com>:
> Loic Quertenmont wrote:
> >
> > I have just found the error
> >
> > FILE * fp = fopen(out_file, "w");
> > -->
> > FILE * fp = fopen(out_file, "wb");
> >
> > Because we are working with binary files and not txt file.
> > the strange thing is that it works perfectly under linux (strange
> strange
> > ;) )
> >
> > 2008/6/30, Joe Nardone <jnardone_at_gmail.com>:
> > > > curl_easy_setopt(session, CURLOPT_WRITEFUNCTION, fwrite);
> > >
> > > What is your implementation of the "fwrite" function?
> > >
> > > If this is the c-library "fwrite" then you have not read the docs
> right.
> > >
> > > j
> > >
>
> Basically, you are using the default behavior of libcurl, but doing so
> in a way which may confuse future maintainers of your code.
>
> All you really have to do is
> - perform your fopen() call with whatever options you want,
> - pass the FILE * variable to libcurl via the CURLOPT_WRITEDATA option,
> and
> - set the write callback function to NULL.
>
> Libcurl will guarantee that this works across all platforms, and not
> just linux.
>
> See
> http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTWRITEFUNCTION
> http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTWRITEDATA
>
> Cheers,
> Gary
>
Received on 2008-06-30