logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: 03cddb25407188283aed415571a30c43fdc0f4c6
parent e71a0c3461d8214872bcc231ab6aaec4af759811
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat, 24 Sep 2022 05:13:11 +0200

cmd/cat: Always prefix error message with "cat: "

Diffstat:

Mcmd/cat.c8++++----
Mtest-cmd/cat14+++++++-------
2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/cmd/cat.c b/cmd/cat.c @@ -19,14 +19,14 @@ concat(int fd, const char *fdname) { if(write(1, buf, (size_t)c) < 0) { - fprintf(stderr, "\nError writing: %s\n", strerror(errno)); + fprintf(stderr, "cat: Error writing: %s\n", strerror(errno)); return 1; } } if(c < 0) { - fprintf(stderr, "\nError reading ‘%s’: %s\n", fdname, strerror(errno)); + fprintf(stderr, "cat: Error reading ‘%s’: %s\n", fdname, strerror(errno)); return 1; } @@ -59,7 +59,7 @@ main(int argc, char *argv[]) int fd = open(argv[argi], O_RDONLY); if(fd < 0) { - fprintf(stderr, "\nError opening ‘%s’: %s\n", argv[argi], strerror(errno)); + fprintf(stderr, "cat: Error opening ‘%s’: %s\n", argv[argi], strerror(errno)); return 1; } @@ -70,7 +70,7 @@ main(int argc, char *argv[]) if(close(fd) < 0) { - fprintf(stderr, "\nError closing ‘%s’: %s\n", argv[argi], strerror(errno)); + fprintf(stderr, "cat: Error closing ‘%s’: %s\n", argv[argi], strerror(errno)); return 1; } } diff --git a/test-cmd/cat b/test-cmd/cat @@ -29,7 +29,7 @@ noperm_body() { touch inputs/chmod_000 || atf_fail "touching chmod_000" chmod 0000 inputs/chmod_000 || atf_fail "chmod 0000 chmod_000" # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:\nError opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/cat inputs/chmod_000 + atf_check -s exit:1 -e 'inline:cat: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/cat inputs/chmod_000 } noperm_cleanup() { chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000" @@ -38,9 +38,9 @@ noperm_cleanup() { atf_test_case devfull devfull_body() { - atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../cmd/cat inputs/all_bytes >/dev/full' - atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../cmd/cat <inputs/all_bytes >/dev/full' - atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../cmd/cat - <inputs/all_bytes >/dev/full' + atf_check -s exit:1 -e 'inline:cat: Error writing: No space left on device\n' sh -c '../cmd/cat inputs/all_bytes >/dev/full' + atf_check -s exit:1 -e 'inline:cat: Error writing: No space left on device\n' sh -c '../cmd/cat <inputs/all_bytes >/dev/full' + atf_check -s exit:1 -e 'inline:cat: Error writing: No space left on device\n' sh -c '../cmd/cat - <inputs/all_bytes >/dev/full' } atf_test_case readslash @@ -48,20 +48,20 @@ readslash_body() { [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD allows to read directories" # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:\nError reading ‘/’: Is a directory\n' ../cmd/cat / + atf_check -s exit:1 -e 'inline:cat: Error reading ‘/’: Is a directory\n' ../cmd/cat / } atf_test_case enoent enoent_body() { # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:\nError opening ‘/var/empty/e/no/ent’: No such file or directory\n' ../cmd/cat /var/empty/e/no/ent + atf_check -s exit:1 -e 'inline:cat: Error opening ‘/var/empty/e/no/ent’: No such file or directory\n' ../cmd/cat /var/empty/e/no/ent } atf_test_case doubledash doubledash_body() { atf_check -o file:inputs/all_bytes -- ../cmd/cat -- inputs/all_bytes # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:\nError opening ‘---’: No such file or directory\n' -o empty -- ../cmd/cat --- inputs/all_bytes + atf_check -s exit:1 -e 'inline:cat: Error opening ‘---’: No such file or directory\n' -o empty -- ../cmd/cat --- inputs/all_bytes } atf_init_test_cases() {