From 788cfd8bcc932e545db73da282c48a9bad8ca271 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 31 Jul 2025 02:43:02 +0900 Subject: feat: implement __FILE__ macro --- io.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 io.c (limited to 'io.c') diff --git a/io.c b/io.c new file mode 100644 index 0000000..6c92b20 --- /dev/null +++ b/io.c @@ -0,0 +1,31 @@ +struct InFile { + const char* filename; + char* buf; +}; +typedef struct InFile InFile; + +InFile* read_all(const char* filename) { + FILE* in; + if (strcmp(filename, "-") == 0) { + in = stdin; + } else { + in = fopen(filename, "rb"); + } + if (!in) { + return NULL; + } + char* buf = calloc(1024 * 1024, sizeof(char)); + char* cur = buf; + char* tmp = calloc(1024, sizeof(char)); + while (fgets(tmp, 1024, in)) { + size_t len = strlen(tmp); + memcpy(cur, tmp, len); + cur += len; + } + fclose(in); + + InFile* in_file = calloc(1, sizeof(InFile)); + in_file->filename = filename; + in_file->buf = buf; + return in_file; +} -- cgit v1.2.3-70-g09d2