diff options
| author | user <user@clank> | 2026-07-16 13:07:28 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-07-16 13:07:28 +0200 |
| commit | fc6f690727aac2b5c9bd368f9b13188fb0ba36a7 (patch) | |
| tree | 5cf80045737ddcd267d484318fa782ba5faf7efb /c/cat.c | |
| parent | fs rewrite stage 3: nested directories, paths, cwd (cd/mkdir/ls) (diff) | |
| download | gbos-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 '')
| -rw-r--r-- | c/cat.c | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -6,7 +6,8 @@ void main(void) { if (argc > 0) { unsigned char fd = open(argv[0], O_READ); int ch; - if (fd == NOFD) { puts("cat: no such file"); nl(); return; } + if (fd == EISDIR) { puts("cat: is a directory"); nl(); return; } + if (fd == NOFD) { puts("cat: no such file"); nl(); return; } while ((ch = fgetc(fd)) >= 0) putc((char)ch); close(fd); } else { |
