aboutsummaryrefslogtreecommitdiff
path: root/src/download.c
diff options
context:
space:
mode:
authorforever2k38 <forever2k38@noreply.codeberg.org>2026-09-04 12:45:43 +0200
committerforever2k38 <forever2k38@noreply.codeberg.org>2026-09-04 12:45:43 +0200
commit7bf3c5b692f34bd6d9467ac3c651692c885a1d90 (patch)
treeea2d9abb30b1e4ce5451b52c11d782f6d14e5686 /src/download.c
parented979ea2b7cc0caf3abb47dce94e02ef16c73e65 (diff)
filesystem fuckery
Diffstat (limited to 'src/download.c')
-rw-r--r--src/download.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/download.c b/src/download.c
new file mode 100644
index 0000000..bb8365c
--- /dev/null
+++ b/src/download.c
@@ -0,0 +1,40 @@
+#include "curl/curl.h"
+#include "stdio.h"
+
+static size_t write_cb(char *ptr, size_t size, size_t nmemb, void *stream) {
+ size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
+
+ return written;
+}
+
+int pow_download_file(char *path, char *url) {
+ FILE *pagefile;
+ CURL *curl = curl_easy_init();
+
+ if (!curl) {
+ printf("failed to init curl\n");
+
+ return 1;
+ }
+
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
+
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
+
+ pagefile = fopen(path, "wb");
+
+ if (!pagefile) {
+ curl_easy_cleanup(curl);
+
+ return 1;
+ }
+
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, pagefile);
+
+ int result = curl_easy_perform(curl);
+
+ fclose(pagefile);
+
+ return result;
+}