aboutsummaryrefslogtreecommitdiff
path: root/teensy/teensy_common.c
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-05-10 00:28:14 -0400
committeriamcheeseman <[email protected]>2026-05-10 00:28:14 -0400
commit576bd27e11ec70bdbd1b9a644d2e227b57586337 (patch)
tree2dc41e3f88bb95568f73ee372fc35512afcbcf9b /teensy/teensy_common.c
parent9ed5698b3c74c7ce1784d3bebe2aa73d5a0c319d (diff)
i ain't splitting alla this up
Diffstat (limited to 'teensy/teensy_common.c')
-rw-r--r--teensy/teensy_common.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/teensy/teensy_common.c b/teensy/teensy_common.c
new file mode 100644
index 0000000..96d589e
--- /dev/null
+++ b/teensy/teensy_common.c
@@ -0,0 +1,30 @@
+#include "teensy_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)
+ ty_log_fatal(TY_ERR_IO, "could not open file '%s'", path);
+
+ fseek(file, 0L, SEEK_END);
+ size_t size = ftell(file);
+ rewind(file);
+
+ char *dat = ty_alloc(sizeof(char) * (size + 1));
+
+ size_t bytes_read = fread(dat, sizeof(char), size, file);
+
+ if (bytes_read < size) {
+ ty_log_fatal(TY_ERR_IO, "could not read file '%s'", path);
+ }
+
+ fclose(file);
+
+ if (size_out)
+ *size_out = size;
+
+ return dat;
+}