X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/8fce4520de1f257819b16f9253fa28dcdae743f4..0765e7c133eb393d8cd0292af444543c2edf8ccc:/lunaix-os/usr/cat/main.c diff --git a/lunaix-os/usr/cat/main.c b/lunaix-os/usr/cat/main.c index 0a15f8c..9f0d35b 100644 --- a/lunaix-os/usr/cat/main.c +++ b/lunaix-os/usr/cat/main.c @@ -11,14 +11,26 @@ int main(int argc, const char* argv[]) { int fd = 0; - unsigned int size = 0; + int size = 0; + struct file_stat stat; for (int i = 1; i < argc; i++) { fd = open(argv[i], FO_RDONLY); + if (fd < 0) { printf("open failed: %s (error: %d)", argv[i], fd); continue; } + if (fstat(fd, &stat) < 0) { + printf("fail to get stat %d\n", errno); + return 1; + } + + if (!(stat.mode & F_MFILE)) { + printf("%s is a directory", argv[i]); + return 1; + } + do { size = read(fd, buffer, BUFSIZE); write(stdout, buffer, size);