aboutsummaryrefslogtreecommitdiffhomepage
path: root/io.c
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-07-31 02:43:02 +0900
committernsfisis <nsfisis@gmail.com>2025-08-15 10:06:18 +0900
commit788cfd8bcc932e545db73da282c48a9bad8ca271 (patch)
treeb386b8a6f2f1dc7a6042c15f13b2d929635816e5 /io.c
parent8fba2c682d190236b0e4c82b71404e6cfb62d6d0 (diff)
downloadducc-788cfd8bcc932e545db73da282c48a9bad8ca271.tar.gz
ducc-788cfd8bcc932e545db73da282c48a9bad8ca271.tar.zst
ducc-788cfd8bcc932e545db73da282c48a9bad8ca271.zip
feat: implement __FILE__ macro
Diffstat (limited to 'io.c')
-rw-r--r--io.c31
1 files changed, 31 insertions, 0 deletions
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;
+}