logo

utils

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

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

Diffstat:

Mcmd/date.c16++++++++--------
Mtest-cmd/date6+++---
2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/cmd/date.c b/cmd/date.c @@ -20,7 +20,7 @@ custom_datetime(time_t *now, char *optarg) *now = (time_t)strtol(optarg, NULL, 10); if(errno != 0) { - perror("strtol"); + perror("date: strtol"); return 0; } @@ -51,7 +51,7 @@ main(int argc, char *argv[]) now = time(NULL); if(now == (time_t)-1) { - perror("time"); + perror("date: time"); exit(EXIT_FAILURE); } @@ -69,11 +69,11 @@ main(int argc, char *argv[]) uflag++; break; case ':': - fprintf(stderr, "Error: Missing operand for option: '-%c'\n", optopt); + fprintf(stderr, "date: Error: Missing operand for option: '-%c'\n", optopt); usage(); return 1; case '?': - fprintf(stderr, "Error: Unrecognised option: '-%c'\n", optopt); + fprintf(stderr, "date: Error: Unrecognised option: '-%c'\n", optopt); usage(); return 1; } @@ -85,7 +85,7 @@ main(int argc, char *argv[]) if(tm == NULL) { - perror("gmtime"); + perror("date: gmtime"); exit(EXIT_FAILURE); } } @@ -95,7 +95,7 @@ main(int argc, char *argv[]) if(tm == NULL) { - perror("localtime"); + perror("date: localtime"); exit(EXIT_FAILURE); } } @@ -110,13 +110,13 @@ main(int argc, char *argv[]) errno = 0; if(strftime(outstr, sizeof(outstr), format, tm) == 0 && errno != 0) { - perror("strftime"); + perror("date: strftime"); exit(EXIT_FAILURE); } if(puts(outstr) < 0) { - perror("puts"); + perror("date: puts"); exit(EXIT_FAILURE); } diff --git a/test-cmd/date b/test-cmd/date @@ -9,7 +9,7 @@ noargs_body() { atf_test_case badarg badarg_body() { - atf_check -s 'exit:1' -e "inline:Error: Unrecognised option: '-x'\ndate [-u][-d datetime] [+format]\n" ../cmd/date -x + atf_check -s 'exit:1' -e "inline:date: Error: Unrecognised option: '-x'\ndate [-u][-d datetime] [+format]\n" ../cmd/date -x } atf_test_case epoch @@ -38,7 +38,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:puts: No space left on device\n' sh -c '../cmd/date >/dev/full' + atf_check -s exit:1 -e 'inline:date: puts: No space left on device\n' sh -c '../cmd/date >/dev/full' } atf_test_case utc @@ -52,7 +52,7 @@ timestamp_body() { atf_check -o "inline:1970-01-01T00:01:09\n" ../cmd/date -u -d @69 '+%FT%T' atf_check -o "inline:1969-12-31T23:58:51\n" ../cmd/date -u -d @-69 '+%FT%T' - atf_check -s 'exit:1' -e "inline:Error: Missing operand for option: '-d'\ndate [-u][-d datetime] [+format]\n" ../cmd/date -u -d + atf_check -s 'exit:1' -e "inline:date: Error: Missing operand for option: '-d'\ndate [-u][-d datetime] [+format]\n" ../cmd/date -u -d atf_check -s 'exit:1' ../cmd/date -u -d 69 # 36893488147419103232 = 2^65