#include <stdio.h> #include <string.h> #include <sys/types.h> #include <fcntl.h> #include <stdlib.h> #include <curl/curl.h> void main() { CURL *curl; CURLcode curl_res; CURLINFO info; char tmp_file[] = "cstrike.wad"; FILE *tmp; double c_length, time_transfer, download_speed; if ((tmp = fopen(tmp_file,"w")) == NULL) { printf("Невозможно произвести запись на диск\n"); exit(1); } curl = curl_easy_init(); curl_easy_setopt(curl,CURLOPT_URL,"http://cs.matrixhome.net/cs_download/cstrike.wad"); curl_easy_setopt(curl,CURLOPT_WRITEDATA,tmp); if ((curl_res = curl_easy_perform(curl)) != 0) { printf("Ошибка загрузки\n"); exit(1); } curl_easy_getinfo(curl,CURLINFO_SIZE_DOWNLOAD,&c_length); printf("size of file: %g bytes\n",c_length); curl_easy_getinfo(curl,CURLINFO_SPEED_DOWNLOAD,&download_speed); printf("downloaded speed: %g kb/sec\n",download_speed/1024); fflush(tmp); fclose(tmp); curl_easy_cleanup(curl); } |