logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 924d3677d2c0720dc0fede0d002c87b137ff26e2
parent 3d0bfe28993baf50113802c6c63e59d6451939c8
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 20 Sep 2024 03:38:59 +0200

cmd/pathchk: unify error message formatting

Diffstat:

Mcmd/pathchk.c17+++++++++--------
Mtest-cmd/pathchk.sh14+++++++-------
2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/cmd/pathchk.c b/cmd/pathchk.c @@ -57,11 +57,11 @@ main(int argc, char *argv[]) name_max = _POSIX_NAME_MAX; break; case ':': - fprintf(stderr, "realpath: Error: Missing operand for option: '-%c'\n", optopt); + fprintf(stderr, "pathchk: error: Missing operand for option: '-%c'\n", optopt); usage(); return 1; case '?': - fprintf(stderr, "realpath: Error: Unrecognised option: '-%c'\n", optopt); + fprintf(stderr, "pathchk: error: Unrecognised option: '-%c'\n", optopt); usage(); return 1; } @@ -85,7 +85,7 @@ main(int argc, char *argv[]) if(opt_P && len == 0) { - fprintf(stderr, "pathchk: Operand number %d is empty\n", i); + fprintf(stderr, "pathchk: error: Operand number %d is empty\n", i); err = 1; } @@ -93,7 +93,7 @@ main(int argc, char *argv[]) if(len > path_max) { fprintf(stderr, - "pathchk: Path (%zd octets) is over the maximum size (%zd octets): %s\n", + "pathchk: error: Path (%zd octets) is over the maximum size (%zd octets): %s\n", len, path_max, path); @@ -106,7 +106,7 @@ main(int argc, char *argv[]) if(p == NULL || p[0] == 0) break; if(p[0] == '-' && opt_P) { - fprintf(stderr, "pathchk: Path component starts with an hyphen: %s\n", p); + fprintf(stderr, "pathchk: error: Path component starts with an hyphen: %s\n", p); err = 1; } @@ -115,7 +115,8 @@ main(int argc, char *argv[]) if(name_len > name_max) { fprintf(stderr, - "pathchk: Path component (%zd octets) is over the maximum size (%zd octets): %s\n", + "pathchk: error: Path component (%zd octets) is over the maximum size (%zd " + "octets): %s\n", name_len, name_max, p); @@ -129,7 +130,7 @@ main(int argc, char *argv[]) if(access(path, F_OK) < 0 && errno != ENOENT) { fprintf(stderr, - "pathchk: Error while checking '%s' against filesystem: %s\n", + "pathchk: error: Failed checking '%s' against filesystem: %s\n", path, strerror(errno)); errno = 0; @@ -142,7 +143,7 @@ main(int argc, char *argv[]) if(c_pcs != 0) { fprintf(stderr, - "pathchk: Error non-portable character '%c' (0x%02x) found in: %s\n", + "pathchk: error: Non-portable character '%c' (0x%02x) found in: %s\n", c_pcs, c_pcs, path); diff --git a/test-cmd/pathchk.sh b/test-cmd/pathchk.sh @@ -23,32 +23,32 @@ echo "# PATH_MAX: ${PATH_MAX?}" name_max_str=$(printf "%*s" "${NAME_MAX}" | tr ' ' _) t name_max:ok "foo/${name_max_str}/bar" -t --exit=1 name_max:xfail "foo/s${name_max_str}/bar" "pathchk: Path component ($(( ${NAME_MAX} + 1 )) octets) is over the maximum size (${NAME_MAX} octets): s${name_max_str} +t --exit=1 name_max:xfail "foo/s${name_max_str}/bar" "pathchk: error: Path component ($(( ${NAME_MAX} + 1 )) octets) is over the maximum size (${NAME_MAX} octets): s${name_max_str} " posix_name_max_str=$(printf "%*s" "${POSIX_NAME_MAX}" | tr ' ' _) t posix_name_max:ok "-p foo/${posix_name_max_str}/bar" -t --exit=1 posix_name_max:xfail "-p foo/s${posix_name_max_str}/bar" "pathchk: Path component ($(( ${POSIX_NAME_MAX} + 1 )) octets) is over the maximum size (${POSIX_NAME_MAX} octets): s${posix_name_max_str} +t --exit=1 posix_name_max:xfail "-p foo/s${posix_name_max_str}/bar" "pathchk: error: Path component ($(( ${POSIX_NAME_MAX} + 1 )) octets) is over the maximum size (${POSIX_NAME_MAX} octets): s${posix_name_max_str} " path_max_str=$(printf "%*s" "$(( ${PATH_MAX} - 1 ))" | tr ' ' /) t path_max:ok "${path_max_str}" -t --exit=1 path_max:xfail "s${path_max_str}" "pathchk: Path (${PATH_MAX} octets) is over the maximum size ($(( ${PATH_MAX} - 1 )) octets): s${path_max_str} +t --exit=1 path_max:xfail "s${path_max_str}" "pathchk: error: Path (${PATH_MAX} octets) is over the maximum size ($(( ${PATH_MAX} - 1 )) octets): s${path_max_str} " posix_path_max_str=$(printf "%*s" "$(( ${POSIX_PATH_MAX} - 1 ))" | tr ' ' /) t posix_path_max:ok "-p ${posix_path_max_str}" -t --exit=1 posix_path_max:xfail "-p s${posix_path_max_str}" "pathchk: Path (${POSIX_PATH_MAX} octets) is over the maximum size ($(( ${POSIX_PATH_MAX} - 1 )) octets): s${posix_path_max_str} +t --exit=1 posix_path_max:xfail "-p s${posix_path_max_str}" "pathchk: error: Path (${POSIX_PATH_MAX} octets) is over the maximum size ($(( ${POSIX_PATH_MAX} - 1 )) octets): s${posix_path_max_str} " t enoent /dev/null/foo t noparent /../foo -t --exit=1 hyphen '-P ./-foo' 'pathchk: Path component starts with an hyphen: -foo +t --exit=1 hyphen '-P ./-foo' 'pathchk: error: Path component starts with an hyphen: -foo ' -t --exit=1 hyphen_subdir '-P ./bar/-foo' 'pathchk: Path component starts with an hyphen: -foo +t --exit=1 hyphen_subdir '-P ./bar/-foo' 'pathchk: error: Path component starts with an hyphen: -foo ' zero_two="$(printf '\02')" -t --exit=1 posix_charset "-p foo${zero_two}bar" "pathchk: Error non-portable character '${zero_two}' (0x02) found in: foo${zero_two}bar +t --exit=1 posix_charset "-p foo${zero_two}bar" "pathchk: error: Non-portable character '${zero_two}' (0x02) found in: foo${zero_two}bar "