From fc6f690727aac2b5c9bd368f9b13188fb0ba36a7 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 16 Jul 2026 13:07:28 +0200 Subject: fs: reject open()/read() on a directory (EISDIR) open() now checks the target's inode type: opening a directory as a file returns $FE (EISDIR) instead of a valid fd, so 'cat docs' no longer streams the raw directory block as bytes. cat reports 'is a directory'; wc/head/save treat any invalid fd (>3) as an open failure. (ls is unaffected - it uses the structural opendir/list path, not open/getb.) --- c/wc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'c/wc.c') diff --git a/c/wc.c b/c/wc.c index 424876d..4fa48ee 100644 --- a/c/wc.c +++ b/c/wc.c @@ -14,10 +14,10 @@ void main(void) { for (i = 0; i < argc; i++) if (argv[i][0] != '-') { fname = argv[i]; break; } if (fname) { fd = open(fname, O_READ); - if (fd == NOFD) { puts("wc: no such file"); nl(); return; } + if (fd > 3) { puts("wc: no such file"); nl(); return; } } for (;;) { - if (fd == NOFD) { char c = readc(); if (c == EOF) break; ch = c; } + if (fd > 3) { char c = readc(); if (c == EOF) break; ch = c; } else { ch = fgetc(fd); if (ch < 0) break; } chars++; if (ch == '\n') lines++; -- cgit v1.3.1-sl0p