@@ -21,9 +21,11 @@ size_t write_curl_data(void *contents, size_t size, size_t nmemb, void *userp) {
21
21
return realsize;
22
22
}
23
23
24
- size_t write_curl_data_file (void *contents, size_t size, size_t nmemb, FILE *fp) {
25
- size_t written = fwrite (contents, size, nmemb, fp);
26
- return written;
24
+ size_t write_curl_data_file (void *contents, size_t size, size_t nmemb, void *userp) {
25
+ size_t realsize = size * nmemb;
26
+ std::ofstream *outfile=(std::ofstream*)userp;
27
+ outfile->write ((const char *)contents,realsize);
28
+ return realsize;
27
29
}
28
30
29
31
bool HTTPClient::CheckIfGlobalInitDone ()
@@ -57,7 +59,6 @@ void HTTPClient::SetGlobalOptions(void *curlobj)
57
59
curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1 );
58
60
curl_easy_setopt (curl, CURLOPT_COOKIEFILE, " domocookie.txt" );
59
61
curl_easy_setopt (curl, CURLOPT_COOKIEJAR, " domocookie.txt" );
60
- curl_easy_setopt (curl, CURLOPT_FORBID_REUSE, 1 );
61
62
}
62
63
63
64
// Configuration functions
@@ -130,8 +131,10 @@ bool HTTPClient::GETBinaryToFile(const std::string &url, const std::string &outp
130
131
if (!CheckIfGlobalInitDone ())
131
132
return false ;
132
133
133
- FILE *fp = fopen (outputfile.c_str (), " wb+" );
134
- if (!fp)
134
+ // open the output file for writing
135
+ std::ofstream outfile;
136
+ outfile.open (outputfile.c_str (),std::ios::out|std::ios::binary|std::ios::trunc);
137
+ if (!outfile.is_open ())
135
138
return false ;
136
139
137
140
CURL *curl=curl_easy_init ();
@@ -141,12 +144,12 @@ bool HTTPClient::GETBinaryToFile(const std::string &url, const std::string &outp
141
144
CURLcode res;
142
145
SetGlobalOptions (curl);
143
146
curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, write_curl_data_file);
144
- curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *)fp );
147
+ curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *)&outfile );
145
148
curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
146
149
res = curl_easy_perform (curl);
147
150
curl_easy_cleanup (curl);
148
151
149
- fclose (fp );
152
+ outfile. close ( );
150
153
151
154
return (res==CURLE_OK);
152
155
}
0 commit comments