commit: 192f297ce8cac1e1a9b7cae51f45044e191ed4be
parent 48d7e4377fea72692d5a896cba7274377e58e2b3
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 24 Sep 2022 05:36:19 +0200
cmd/strings: Always prefix error message with "strings: "
Diffstat:
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/cmd/strings.c b/cmd/strings.c
@@ -33,7 +33,7 @@ print_string(char *buffer, size_t offset)
if(ret < 0)
{
- fprintf(stderr, "\nError writing: %s\n", strerror(errno));
+ fprintf(stderr, "strings: Error writing: %s\n", strerror(errno));
return 1;
}
else
@@ -88,7 +88,7 @@ concat(int fd, const char *fdname)
if(c < 0)
{
- fprintf(stderr, "\nError reading ‘%s’: %s\n", fdname, strerror(errno));
+ fprintf(stderr, "strings: Error reading ‘%s’: %s\n", fdname, strerror(errno));
return 1;
}
@@ -119,7 +119,7 @@ main(int argc, char *argv[])
opt_min_strlen = (size_t)strtonum(optarg, 1, 4096, &errstr);
if(errstr)
{
- fprintf(stderr, "Minimal string length is %s: %s\n", errstr, optarg);
+ fprintf(stderr, "strings: Minimal string length is %s: %s\n", errstr, optarg);
usage();
return 1;
}
@@ -143,7 +143,7 @@ main(int argc, char *argv[])
opt_offset_format = "%zd %s\n";
break;
default:
- fprintf(stderr, "Unknown format: %s\n", optarg);
+ fprintf(stderr, "strings: Unknown format: %s\n", optarg);
usage();
return 1;
}
@@ -173,7 +173,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, "strings: Error opening ‘%s’: %s\n", argv[argi], strerror(errno));
return 1;
}
@@ -184,7 +184,7 @@ main(int argc, char *argv[])
if(close(fd) < 0)
{
- fprintf(stderr, "\nError closing ‘%s’: %s\n", argv[argi], strerror(errno));
+ fprintf(stderr, "strings: Error closing ‘%s’: %s\n", argv[argi], strerror(errno));
return 1;
}
}
diff --git a/test-cmd/strings b/test-cmd/strings
@@ -36,7 +36,7 @@ devfull_body() {
[ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()"
[ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()"
- atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../cmd/strings inputs/strings/true >/dev/full'
+ atf_check -s exit:1 -e 'inline:strings: Error writing: No space left on device\n' sh -c '../cmd/strings inputs/strings/true >/dev/full'
}
atf_test_case noperm cleanup
@@ -44,7 +44,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/strings inputs/chmod_000
+ atf_check -s exit:1 -e 'inline:strings: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/strings inputs/chmod_000
}
noperm_cleanup() {
chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000"
@@ -79,20 +79,20 @@ atf_test_case badformat
badformat_body() {
usage="strings: [-a] [-t format] [-n number] [file...]\n"
- atf_check -s exit:1 -e "inline:Unknown format: t\n${usage}" ../cmd/strings -tt inputs/all_bytes
- atf_check -s exit:1 -e "inline:Unknown format: t\n${usage}" ../cmd/strings -tt /dev/null
- atf_check -s exit:1 -e "inline:Unknown format: t\n${usage}" ../cmd/strings -tt inputs/strings/true
- atf_check -s exit:1 -e "inline:Unknown format: t\n${usage}" ../cmd/strings -tt -n 8 inputs/strings/true
+ atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt inputs/all_bytes
+ atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt /dev/null
+ atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt inputs/strings/true
+ atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt -n 8 inputs/strings/true
}
atf_test_case erange_n
erange_n_body() {
usage="strings: [-a] [-t format] [-n number] [file...]\n"
- atf_check -s exit:1 -e "inline:Minimal string length is too small: 0\n${usage}" -- ../cmd/strings -n 0 inputs/all_bytes
- atf_check -s exit:1 -e "inline:Minimal string length is too large: 4097\n${usage}" -- ../cmd/strings -n 4097 inputs/all_bytes
- atf_check -s exit:1 -e "inline:Minimal string length is invalid: f\n${usage}" -- ../cmd/strings -n f inputs/all_bytes
- atf_check -s exit:1 -e "inline:Minimal string length is invalid: 42f\n${usage}" -- ../cmd/strings -n 42f inputs/all_bytes
+ atf_check -s exit:1 -e "inline:strings: Minimal string length is too small: 0\n${usage}" -- ../cmd/strings -n 0 inputs/all_bytes
+ atf_check -s exit:1 -e "inline:strings: Minimal string length is too large: 4097\n${usage}" -- ../cmd/strings -n 4097 inputs/all_bytes
+ atf_check -s exit:1 -e "inline:strings: Minimal string length is invalid: f\n${usage}" -- ../cmd/strings -n f inputs/all_bytes
+ atf_check -s exit:1 -e "inline:strings: Minimal string length is invalid: 42f\n${usage}" -- ../cmd/strings -n 42f inputs/all_bytes
}
atf_test_case usage