aboutsummaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2021-02-03 00:29:50 +0100
committerJan200101 <sentrycraft123@gmail.com>2021-02-03 00:29:50 +0100
commit9c45dcd0ff02f6aa07927a40a13d050e64cca4ed (patch)
tree484b8d0ac575c83856bf62a7e36b680025fee020 /src/net.c
parentbaca7635a3db27bae911ab6ebe928e5c2cc5a155 (diff)
downloadpolecat-9c45dcd0ff02f6aa07927a40a13d050e64cca4ed.tar.gz
polecat-9c45dcd0ff02f6aa07927a40a13d050e64cca4ed.zip
clean up logic some more
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/net.c b/src/net.c
index b2851db..96e09ca 100644
--- a/src/net.c
+++ b/src/net.c
@@ -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;