cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: FILE errno -1 & Bad file descriptor error

From: squashedfrog <squashedfrog_at_gmail.com>
Date: Wed, 1 Apr 2015 02:11:46 -0400

Could we see you WriteCallback function.

> On Mar 31, 2015, at 10:06 PM, Phil Freeman <eyeball_entertainment_at_hotmail.com> wrote:
>
> Hi folks,
>
>
> I've recently incorporated libcurl into a piece of software in development (vs 2010 exp., c++) which is a plugin for use in a well-known animation package. But I'm coming across an error and are unsure how to navigate it. The error is that when I use the line curl_easy_setopt(curl,CURLOPT_WRITEDATA,fp) the file won't close with fclose(). If I comment out the offending line, the file closes without issue. The code below is pretty much what is being used, minus a few lines used for printing etc:
>
>
> char outfilename[FILENAME_MAX] = " ";
>
> // The path is set here using a custom string
> // element. The path is good - the file turns
> // up in the right location.
> for(int i = 1; i <= save_path.GetLength();)
> {
> outfilename[i-1] = save_path.operator[](i-1);
> i++;
> }
>
> curl = curl_easy_init();
>
> if(curl != NULL)
> {
> fp = fopen(outfilename,"wb");
>
> if(fp == NULL)
> {
> MessageDialog(String("Unable to continue: " + String(strerror(errno)) + ". Returning."));
> curl_easy_cleanup(curl);
> return FALSE;
> }
>
> curl_easy_setopt(curl,CURLOPT_URL,"http://www.google.com/robots.txt");
> curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,WriteCallback);
> curl_easy_setopt(curl,CURLOPT_WRITEDATA,fp); // <-- take mental note of this line
>
> curl_easy_perform(curl);
>
> // why is the file 'closing' with errno -1 (Bad file descriptor) when
> // the curl_easy_setopt(curl,CURLOPT_WRITEDATA,fp) command is called?
>
> int fclo = fclose(fp); // fclose() fails
> if(fclo != NULL)
> {
> GePrint("Close file error: " + String(strerror(errno))); // custom print, prints 'Bad file descriptor'
> }
>
> GePrint("fclose(): " + LongToString(fclo)); // custom print function, prints -1
> curl_easy_cleanup(curl);
> }
>
>
> The file is made in the correct location (I've tried a few both on c: drive and other drives) but the file is always 0kb in size. I'm suspecting it might be a admin privileges issue, but will leave the judgement to someone in the know. No other libraries associated with libcurl are installed other than libcurl itself. Running version 7.41.0. Any assistance appreciated.
>
>
> WickedP
> (Website not yet available.)
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-04-01