aboutsummaryrefslogtreecommitdiff
path: root/teensy/common.c
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-05-08 19:30:44 -0400
committeriamcheeseman <[email protected]>2026-05-08 19:30:44 -0400
commit5625a8626fe303748b205c80f87035593cf2f561 (patch)
tree5e5a5adb6f1265358ae21ec47cd384362345df5a /teensy/common.c
Initial commit
Diffstat (limited to 'teensy/common.c')
-rw-r--r--teensy/common.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/teensy/common.c b/teensy/common.c
new file mode 100644
index 0000000..4da4004
--- /dev/null
+++ b/teensy/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)
+ 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;
+}