summary refs log tree commit diff
diff options
context:
space:
mode:
authorWormHeamer2025-03-08 18:02:10 -0500
committerWormHeamer2025-03-08 18:02:10 -0500
commit630ad3e59da9509962d51ac907496e86aec0c9cc (patch)
treef68f3bb5f282682489e46f20ced7810cffe5f9d5
parentfe60d18369d55f4d97f4aaceb0f828134c3f9440 (diff)
simplify read_all, prevent error on piping into stdin
-rw-r--r--main.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/main.c b/main.c
index 17d0c7c..1f9876e 100644
--- a/main.c
+++ b/main.c
@@ -16,18 +16,9 @@
 
 int read_all(FILE *f, Str *buf, Arena *a) {
 	if (!f) return -1;
-	if (isatty(fileno(f))) {
-		buf->s = a->beg;
-		buf->n = fread(a->beg, 1, (uintptr_t)(a->end - a->beg) - 1, f);
-		a->beg += buf->n;
-	} else {
-		fseek(f, 0, SEEK_END);
-		long ofs = ftell(f);
-		fseek(f, 0, SEEK_SET);
-		buf->n = ofs;
-		buf->s = new_arr(a, char, buf->n);
-		if ((isize)fread(buf->s, 1, buf->n, f) != buf->n) return -1;
-	}
+	buf->s = a->beg;
+	buf->n = fread(a->beg, 1, (uintptr_t)(a->end - a->beg) - 1, f);
+	a->beg += buf->n;
 	return ferror(f) ? -1 : 0;
 }