logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: 89e42f7426d269a44971e383f23e7954530f1e42
parent c6545684641b836a92aefc83c2e712ad6fb88e6e
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 30 Jan 2022 02:19:23 +0100

bin/strings: Fix opening files

Diffstat:

Mbin/strings.c10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/bin/strings.c b/bin/strings.c @@ -113,14 +113,14 @@ main(int argc, char *argv[]) } } - if(argc <= 1) + argc -= optind; + argv += optind; + + if(argc < 1) { return concat(0, "<stdin>"); } - argc -= optind; - argv += optind; - for(int argi = 0; argi < argc; argi++) { if(strncmp(argv[argi], "-", 2) == 0) @@ -133,7 +133,7 @@ main(int argc, char *argv[]) else { int fd = open(argv[argi], O_RDONLY); - if(fd < 0) + if(fd <= 0) { fprintf(stderr, "\nError opening ā€˜%sā€™: %s\n", argv[argi], strerror(errno)); return 1;