I'm developing a little updater for my framework. In particular the file is written in C++ and when i try to download a file using the following code the fopen function returns NULL. But the thing is that i tested this software on different machines with the same OS (Windows 10) and on few of them they returns NULL, the others just download and write the file correctly. Do you have any ideas? I've also tried to TRIM the filename to avoid invisible characters. Here's the code to download the file i used:
std::vector<unsigned char> resp = http_request(url, "GET", NULL, NULL, "", user_agent);
if (resp.empty()) {
send_output("ERROR: No response while downloading: " + url);
return;
}
string filename = url.substr(url.rfind("/") + 1);
filename = trim(filename);
if (filename.empty()) {
filename = "downloaded";
}
FILE* f = fopen(filename.c_str(), "wb");
if (f == NULL) {
log("ERROR: Could not open file for writing: " + filename);
return;
}
fwrite(&resp[0], 1, resp.size(), f);
fclose(f);
Thanks guys for the help!