From 5b05099d44ae6ac962be108f4c0da7493a9305c7 Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Thu, 29 May 2025 20:10:01 -0400 Subject: Initial Commit --- src/io.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/io.c (limited to 'src/io.c') diff --git a/src/io.c b/src/io.c new file mode 100644 index 0000000..78f679a --- /dev/null +++ b/src/io.c @@ -0,0 +1,27 @@ +#include +#include + +bool ReadFile(const char * const path, const size_t n, char * const buffer) { + FILE *fp = fopen(path, "r"); + if (fp == NULL) { + perror("ReadFile: fopen"); + return false; + } + + int j = 0; + size_t i = 0; + for (; i < n - 1; i++) { + j = fgetc(fp); + if (j == EOF) { + break; + } + buffer[i] = (char)j; + } + + buffer[i] = '\0'; + + bool ret = (!ferror(fp) && feof(fp)); + fclose(fp); + return ret; +} + -- cgit v1.2.3