logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: 3bfac2656fbf458a93c281b4cfc4c589c9f2bfef
parent 2634624ac993af9b2c5556f451dc3c7db30232d4
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat, 26 Feb 2022 21:46:17 +0100

bin/cat: Ignore -- (dash-dash) in arguments

Diffstat:

Mbin/cat.c4++++
Mtest-bin/cat7+++++++
2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/bin/cat.c b/bin/cat.c @@ -50,6 +50,10 @@ main(int argc, char *argv[]) return 1; } } + else if(strncmp(argv[argi], "--", 3) == 0) + { + continue; + } else { int fd = open(argv[argi], O_RDONLY); diff --git a/test-bin/cat b/test-bin/cat @@ -62,6 +62,12 @@ enoent_body() { atf_check -s exit:1 -e 'inline:\nError opening β€˜/var/empty/e/no/ent’: No such file or directory\n' ../bin/cat /var/empty/e/no/ent } +atf_test_case doubledash +doubledash_body() { + atf_check -o file:inputs/all_bytes -- ../bin/cat -- inputs/all_bytes + atf_check -s exit:1 -e 'inline:\nError opening β€˜---’: No such file or directory\n' -o empty -- ../bin/cat --- inputs/all_bytes +} + atf_init_test_cases() { cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case allfile @@ -74,4 +80,5 @@ atf_init_test_cases() { atf_add_test_case devfull atf_add_test_case readslash atf_add_test_case enoent + atf_add_test_case doubledash }