1 Star 0 Fork 1

test/update_engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
download.cpp 1.69 KB
一键复制 编辑 原始数据 按行查看 历史
jkand.huang 提交于 2019-03-08 15:27 . update update_engine to v1.0.0
/*************************************************************************
> File Name: download.cpp
> Author: jkand.huang
> Mail: jkand.huang@rock-chips.com
> Created Time: Thu 07 Mar 2019 10:30:31 AM CST
************************************************************************/
#include <stdio.h>
#include <curl/curl.h>
#include "log.h"
size_t my_write_func(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
return fwrite(ptr, size, nmemb, stream);
}
extern double processvalue;
int my_progress_func(char *progress_data,
double t, /* dltotal */
double d, /* dlnow */
double ultotal,
double ulnow)
{
processvalue = ulnow / ultotal * 100 / 110;
return 0;
}
int download_file(char *url, char *output_filename)
{
CURL *curl;
CURLcode res;
FILE *outfile;
char *progress_data = "* ";
curl = curl_easy_init();
if(curl)
{
outfile = fopen(output_filename, "wb");
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_write_func);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, false);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, my_progress_func);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, progress_data);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
LOGE("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
fclose(outfile);
/* always cleanup */
curl_easy_cleanup(curl);
}
if(res != CURLE_OK){
LOGE("download Error.\n");
return -1;
}
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/rockchip/update_engine.git
git@gitee.com:rockchip/update_engine.git
rockchip
update_engine
update_engine
master

搜索帮助