diff options
author | Tyler Murphy <tylerm@tylerm.dev> | 2023-04-28 15:13:10 -0400 |
---|---|---|
committer | Tyler Murphy <tylerm@tylerm.dev> | 2023-04-28 15:13:10 -0400 |
commit | 7a1eef12299f4b030bfb77d9bbb133d0ba2ee674 (patch) | |
tree | 61d7008b25e37799318db4030b86f85fc0059275 /src/commands/cat.c | |
parent | fix missing newline on single row output (diff) | |
download | lazysphere-7a1eef12299f4b030bfb77d9bbb133d0ba2ee674.tar.gz lazysphere-7a1eef12299f4b030bfb77d9bbb133d0ba2ee674.tar.bz2 lazysphere-7a1eef12299f4b030bfb77d9bbb133d0ba2ee674.zip |
add tail
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); |