-CFLAGS = -Wall -Wextra -fsanitize=address -g
-SRC = src/main.c src/cpu.c
-OBJ = build/main.o build/cpu.o
+CFLAGS = -Wall -Wextra -fsanitize=address -g -lcurl
+SRC = src/main.c src/cpu.c src/downloader.c
+OBJ = build/main.o build/cpu.o build/downloader.o
RES = build/Thoryum
all: setup $(OBJ) build
build/cpu.o: src/cpu.c
$(CC) $(CFLAGS) -c $^ -o $@
+build/downloader.o: src/downloader.c
+ $(CC) $(CFLAGS) -c $^ -o $@
+
setup:
mkdir -p build
=== This shit is fire ! How do I use it ? ===
+= Install some stuff =
+
+First you'll need to install the following libs:
+- Standart lib, should work with glibc or musl
+- Libcurl, to download from da web
+
TODO : write some shit about using it
--- /dev/null
+#include <curl/curl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <err.h>
+#include "downloader.h"
+
+// Well its probably usefull
+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;
+}
+
+// Ref : https://curl.se/libcurl/c/simple.html
+// https://curl.se/libcurl/c/url2file.html
+// returns 0 if good or 1 if that failed
+int DL_get_file(char *url, FILE *file) {
+ CURL *curl;
+
+ CURLcode result = curl_global_init(CURL_GLOBAL_ALL);
+ if(result != CURLE_OK) {
+ err(EXIT_FAILURE, "Failed to initialize CURL, Abort\n");
+ return 1;
+ }
+
+ curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); // To debug stuff
+ curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); // We want to see the progress
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb); // func to write some shit
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); // We tell libcurl to follow redirection
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
+
+ result = curl_easy_perform(curl);
+ if(result != CURLE_OK) {
+ err(EXIT_FAILURE, "Failed to perform download : '%s', Abort\n", curl_easy_strerror(result));
+ return 1;
+ }
+
+ curl_easy_cleanup(curl);
+ }
+ curl_global_cleanup();
+ return 0;
+}
#include <stdio.h>
#include "cpu.h"
+#include "downloader.h"
int main() {
printf("Hello this is Thoryum ;)\n");
char opti_name[5] = {0};
CPU_opti_name(opti_name, opti);
printf("You are using the CPU : '%s'\n", opti_name);
+
+ FILE *file = fopen("page.out", "w");
+ DL_get_file("https://ayabusa.dev", file);
+ fclose(file);
}