cURL / Mailing Lists / curl-library / Single Mail

curl-library

[BUGS] curl_easy_perform and Dev C++ crash

From: grz <garzul_at_tiscali.fr>
Date: Fri, 24 Nov 2006 18:17:30 +0100

Hi,

I use CURL for get a text file on the website.
If my file exist or if i'm connected i have no problem but if i'm not
connected or don't file exist on my website CURL crash on
"curl_easy_perform" function.
I think it's a curl_easy_perform return problem but i don't understand why.
The version of libcurl is "libcurl/7.16.0 zlib/1.2.2" on Windows.

See :

FILE *fileg = NULL;
int CURLErr=0;
bool CURLinit=false;
bool CURLok=false;

size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp)
{
   int len = size * nmemb;
   fwrite(buffer,sizeof(unsigned char),len,fileg);

   return len;
}

// Téléchargement fichier
void GetFile(char *url,char *fileout)
{
   fileg = fopen(fileout,"w");

   CURLcode res;
   CURL *c = curl_easy_init();
   char* CErrBuff;

   if (c)
   {
     curl_easy_setopt(c, CURLOPT_FAILONERROR, 1);
     curl_easy_setopt(c, CURLOPT_ERRORBUFFER, CErrBuff);
     curl_easy_setopt(c, CURLOPT_WRITEFUNCTION ,write_data);
     curl_easy_setopt(c, CURLOPT_WRITEDATA, fileg);
     curl_easy_setopt(c, CURLOPT_HEADER, 0);
     curl_easy_setopt(c, CURLOPT_URL,url);
     curl_easy_setopt(c, CURLOPT_NOSIGNAL, 1);
     curl_easy_setopt(c, CURLOPT_CONNECTTIMEOUT, 15);

     res=curl_easy_perform(c);
     if (res != 0)
     {
       switch (res)
       {
         case CURLE_COULDNT_CONNECT:
            log((char*)langs[32].c_str(),false);
            log(url,true);
            CURLErr=1;
            break;
         case CURLE_WRITE_ERROR:
            log((char*)langs[33].c_str(),false);
            log(fileout,true);
            CURLErr=2;
            break;
         case CURLE_OPERATION_TIMEOUTED:
            log((char*)langs[34].c_str(),false);
            log(url,true);
            CURLErr=3;
            break;
         default:
            log((char*)langs[35].c_str(),false);
            log(url,false);
            log(" ",false);
            log(fileout,true);
            CURLErr=4;
       }
     }
     else
     {
       CURLok=true;
     }

     curl_easy_cleanup(c);

   }
   else
   {
    log((char*)langs[36].c_str(),false);
    exit(0);
   }

   fclose(fileg);

}

-- 
Grz- //Opera//
Received on 2006-11-24