diff options
author | Jan200101 <sentrycraft123@gmail.com> | 2021-02-03 00:29:50 +0100 |
---|---|---|
committer | Jan200101 <sentrycraft123@gmail.com> | 2021-02-03 00:29:50 +0100 |
commit | 9c45dcd0ff02f6aa07927a40a13d050e64cca4ed (patch) | |
tree | 484b8d0ac575c83856bf62a7e36b680025fee020 /src/net.c | |
parent | baca7635a3db27bae911ab6ebe928e5c2cc5a155 (diff) | |
download | polecat-9c45dcd0ff02f6aa07927a40a13d050e64cca4ed.tar.gz polecat-9c45dcd0ff02f6aa07927a40a13d050e64cca4ed.zip |
clean up logic some more
Diffstat (limited to 'src/net.c')
-rw-r--r-- | src/net.c | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -10,7 +10,7 @@ #include "net.h" #include "common.h" -static size_t memoryCallback(void* contents, size_t size, size_t nmemb, void* userp) +static inline size_t memoryCallback(void* contents, size_t size, size_t nmemb, void* userp) { size_t realsize = size * nmemb; struct MemoryStruct* mem = (struct MemoryStruct*)userp; @@ -30,7 +30,7 @@ static size_t memoryCallback(void* contents, size_t size, size_t nmemb, void* us return realsize; } -static int xferinfo(UNUSED void *p, curl_off_t dltotal, curl_off_t dlnow, UNUSED curl_off_t ultotal, UNUSED curl_off_t ulnow) +static inline int xferinfo(UNUSED void *p, curl_off_t dltotal, curl_off_t dlnow, UNUSED curl_off_t ultotal, UNUSED curl_off_t ulnow) { curl_off_t progress = 0; if (dltotal != 0) @@ -99,6 +99,25 @@ struct MemoryStruct* downloadToRam(const char* URL, long noprogress) return chunk; } +void downloadToFile(const char* URL, const char* path) +{ + struct MemoryStruct* chunk = downloadToRam(URL, 1L); + + if (chunk) + { + FILE* fp = fopen(path, "wb"); + + if (fp) + { + fwrite(chunk->memory, sizeof(uint8_t), chunk->size, fp); + fclose(fp); + } + + free(chunk->memory); + free(chunk); + } +} + struct json_object* fetchJSON(const char* URL) { struct MemoryStruct* chunk = downloadToRam(URL, 1L); @@ -111,7 +130,6 @@ struct json_object* fetchJSON(const char* URL) free(chunk->memory); free(chunk); - } return json; |