From 5625a8626fe303748b205c80f87035593cf2f561 Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Fri, 8 May 2026 19:30:44 -0400 Subject: Initial commit --- teensy/common.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 teensy/common.c (limited to 'teensy/common.c') 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 +#include + +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; +} -- cgit v1.3-2-g0d8e