From 73843fa284968b4efb0ae51858cb37d0189c4b83 Mon Sep 17 00:00:00 2001 From: Nic Gaffney Date: Wed, 28 Jun 2023 16:21:15 -0500 Subject: filer added to std --- std/stdio.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'std/stdio.c') diff --git a/std/stdio.c b/std/stdio.c index f6dbeaf..b5f1dd0 100644 --- a/std/stdio.c +++ b/std/stdio.c @@ -26,3 +26,23 @@ void curshide() { void cursshow() { print("\x1b[?25h"); } + +char* filer(char* path) { + FILE *fptr = fopen(path, "rb"); + char *contents = 0; + + if(fptr == NULL) { + return "File not found"; + } + fseek(fptr, 0, SEEK_END); + long size = ftell(fptr); + fseek(fptr, 0, SEEK_SET); + + contents = malloc(size); + fread(contents, 1, size, fptr); + fclose(fptr); + + return contents; +} + + -- cgit v1.2.3