summaryrefslogtreecommitdiff
path: root/common/common.c
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-04-06 17:04:05 -0400
committeriamcheeseman <[email protected]>2026-04-06 17:06:53 -0400
commit957c64c7b8b5e98d8a03dd84c7e27e7991fb9dbc (patch)
treef5fc230703791cee8d8e7851fb87eaef07ae63a2 /common/common.c
Initial commit
Diffstat (limited to 'common/common.c')
-rw-r--r--common/common.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/common/common.c b/common/common.c
new file mode 100644
index 0000000..d38f7ac
--- /dev/null
+++ b/common/common.c
@@ -0,0 +1,30 @@
+#include "common.h"
+
+#include <stdarg.h>
+#include <stdio.h>
+
+char *read_file(const char *path, size_t *size_out)
+{
+ FILE *file = fopen(path, "r");
+ if (!file)
+ log_fatal(ERR_IO, "could not open file '%s'", path);
+
+ fseek(file, 0L, SEEK_END);
+ size_t size = ftell(file);
+ rewind(file);
+
+ char *dat = mem_alloc(sizeof(char) * (size + 1));
+
+ size_t bytes_read = fread(dat, sizeof(char), size, file);
+
+ if (bytes_read < size) {
+ log_fatal(ERR_IO, "could not read file '%s'", path);
+ }
+
+ fclose(file);
+
+ if (size_out)
+ *size_out = size;
+
+ return dat;
+}