cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re:FILE errno -1 & Bad file descriptor error

From: À¼Ìì <lantian0811_at_163.com>
Date: Wed, 1 Apr 2015 19:48:56 +0800 (CST)

At 2015-04-01 10:06:45, "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'
> }
Here , this error indicate that the fd has been closed before, so here means close the same fd two times. I suffer the similar problem ,however I do not find the solution!
> 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