I'm trying to make a callback function, and then write the content retrieved into a file using libcurl
. The program works nicely in Linux
and Windows
, however, the fopen
operation fails in solarix_x86
. myvector
contains a list of url files to be copied, and PATH_SEPARATOR
is a macro which formats the string path, depending on the platform (Unix
, Windows
).
vector<string>::iterator it;
for( it=myvector.begin() ; it < myvector.end(); it++ ){
string dest = "/home/files/" + PATH_SEPARATOR + *it // PATH_SEPARATOR IS A MACRO
curl_easy_setopt(curl, CURLOPT_URL, it->c_str());
curl_easy_setopt(curl, CURL_WRITEFUNCTION, write_data);
file = fopen(dest.c_str(), "w+b");
if(file == NULL){
throw std::runtime_error("FILE IS NULL, CAN'T OPEN\n");
}
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
curl_easy_perform(curl);
fclose(file);
}
And function write_data
:
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream){
size_t written = fwrite(ptr, size, nmemb, (FILE*)stream);
return written;
}
I'm suspecting is something related to the "w+b"
flag.... Any thoughts?
************ UPDATE **********
errno=2
.