bore

Unnamed repository
Log | Files | Refs

commit a1ba22ff44110d3ccb93d6f5a0313abc370d55e7
parent cb98d9607e45ec1cd3469a731bc4dc3f9f5ad01a
Author: aabacchus <ben@bvnf.space>
Date:   Thu, 16 Sep 2021 03:29:36 +0100

cat: add -u

Diffstat:
Mcat.c | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/cat.c b/cat.c @@ -25,6 +25,11 @@ cat(int fd, char *fname) { int main(int argc, char **argv) { + if (argc > 1 && **(argv+1) == '-' && *(*(argv+1)+1) == 'u') { + /* ignore -u */ + argv++; + argc--; + } if (argc == 1) return cat(0, "stdin"); @@ -33,7 +38,7 @@ main(int argc, char **argv) { char *fname; while (*++argv) { - if (**argv == '-') { + if (**argv == '-' && *(*argv + 1) == '\0') { fd = 0; fname = "stdin"; } else { @@ -49,7 +54,7 @@ main(int argc, char **argv) { err = 1; continue; } - if (close(fd) == -1){ + if (fd != 0 && close(fd) == -1){ fprintf(stderr, "cat: close %s: %s\n", fname, strerror(errno)); err = 1; }