From b047be5252aeb981faea077409c1768fda0301d9 Mon Sep 17 00:00:00 2001 From: Omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sat, 24 Feb 2024 11:43:13 +1100 Subject: xmake init with shared/static lib --- src/platform/file.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/platform/file.c (limited to 'src/platform/file.c') diff --git a/src/platform/file.c b/src/platform/file.c new file mode 100644 index 0000000..497a95c --- /dev/null +++ b/src/platform/file.c @@ -0,0 +1,29 @@ +#include "file.h" + +#include +#include +#include +#include + +const char *string_from_file(const char *path) { + FILE *f = fopen(path, "rb"); + if (f == NULL) { + // ERROR("Error reading file: %s. errno: %d", path, errno); + return NULL; + } + if (ferror(f)) { + // ERROR("Error reading file: %s. errno: %d", path, errno); + return NULL; + } + fseek(f, 0, SEEK_END); + long fsize = ftell(f); + rewind(f); + + char *string = malloc(fsize + 1); + fread(string, fsize, 1, f); + fclose(f); + + string[fsize] = '\0'; + + return string; +} \ No newline at end of file -- cgit v1.2.3-70-g09d2