aboutsummaryrefslogtreecommitdiff
path: root/src/io
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-08 12:00:49 +0200
committerhachem <im@hachem.wtf>2026-09-08 12:00:49 +0200
commit9d47486aac9cd1a4422b78ee273b7a27bf7b733a (patch)
treea015067fe963f3a24e8f37a8b9cd581540b3bb8c /src/io
parent21be45a904a0afc767214298721bd2bbce19a054 (diff)
refactor: flatten src and migrate to meson
Diffstat (limited to 'src/io')
-rw-r--r--src/io/file.c69
-rw-r--r--src/io/file.h13
2 files changed, 0 insertions, 82 deletions
diff --git a/src/io/file.c b/src/io/file.c
deleted file mode 100644
index 3d7083c..0000000
--- a/src/io/file.c
+++ /dev/null
@@ -1,69 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "diag/diag.h"
-#include "io/file.h"
-
-static void report_file_error(const char* verb, const char* path)
-{
- char message[512];
- snprintf(message, sizeof(message), "%s '%s'", verb, path);
- report_error_message(message);
-}
-
-bool read_file(const char* path, struct File* out)
-{
- FILE* stream = fopen(path, "rb");
- if (stream == NULL)
- {
- report_file_error("could not open", path);
- return false;
- }
-
- if (fseek(stream, 0, SEEK_END) != 0)
- {
- report_file_error("could not read", path);
- fclose(stream);
- return false;
- }
-
- long length = ftell(stream);
- if (length < 0)
- {
- report_file_error("could not read", path);
- fclose(stream);
- return false;
- }
- rewind(stream);
-
- size_t size = (size_t)length;
- char* data = malloc(size + 1);
- if (data == NULL)
- {
- report_file_error("out of memory reading", path);
- fclose(stream);
- return false;
- }
-
- if (fread(data, 1, size, stream) != size)
- {
- report_file_error("could not read", path);
- free(data);
- fclose(stream);
- return false;
- }
-
- data[size] = '\0';
- fclose(stream);
-
- out->data = data;
- out->size = size;
- return true;
-}
-
-void free_file(struct File* file)
-{
- free(file->data);
- file->data = NULL;
- file->size = 0;
-}
diff --git a/src/io/file.h b/src/io/file.h
deleted file mode 100644
index 7d15bd0..0000000
--- a/src/io/file.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#pragma once
-
-#include <stddef.h>
-#include <stdbool.h>
-
-struct File
-{
- char* data;
- size_t size;
-};
-
-bool read_file(const char* path, struct File* out);
-void free_file(struct File* file);