aboutsummaryrefslogtreecommitdiffstats
path: root/c/head.c
diff options
context:
space:
mode:
authoruser <user@clank>2026-07-16 13:07:28 +0200
committeruser <user@clank>2026-07-16 13:07:28 +0200
commitfc6f690727aac2b5c9bd368f9b13188fb0ba36a7 (patch)
tree5cf80045737ddcd267d484318fa782ba5faf7efb /c/head.c
parentfs rewrite stage 3: nested directories, paths, cwd (cd/mkdir/ls) (diff)
downloadgbos-fc6f690727aac2b5c9bd368f9b13188fb0ba36a7.tar.gz
gbos-fc6f690727aac2b5c9bd368f9b13188fb0ba36a7.tar.xz
gbos-fc6f690727aac2b5c9bd368f9b13188fb0ba36a7.zip
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.)
Diffstat (limited to 'c/head.c')
-rw-r--r--c/head.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/c/head.c b/c/head.c
index e8bf846..3298e54 100644
--- a/c/head.c
+++ b/c/head.c
@@ -16,10 +16,10 @@ void main(void) {
}
if (fname) {
fd = open(fname, O_READ);
- if (fd == NOFD) { puts("head: no such file"); nl(); return; }
+ if (fd > 3) { puts("head: 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; }
if (lines < n) putc((char)ch);
if (ch == '\n') lines++;