diff options
Diffstat (limited to 'src/commands/cat.c')
-rw-r--r-- | src/commands/cat.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/commands/cat.c b/src/commands/cat.c index f5622e8..8e22706 100644 --- a/src/commands/cat.c +++ b/src/commands/cat.c @@ -1,7 +1,9 @@ #include "../command.h" #include <ctype.h> +#include <errno.h> #include <string.h> +#include <sys/stat.h> struct Flags { bool number_lines; @@ -138,6 +140,15 @@ COMMAND(cat) { continue; } else { files = true; + struct stat s; + if (stat(argv[i], &s) < 0) { + printf("error: failed to read %s: %s\n", argv[i], strerror(errno)); + continue; + } + if (!S_ISREG(s.st_mode)) { + printf("error: %s is not a file\n", argv[i]); + continue; + } FILE* in = get_file(argv[i], "r"); cat_file(in, flags); fclose(in); |