logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 33515c4fd533d1cfdeb02b3cc124d47d660b3f9a
parent 1b43292c1940bf4c6da94ada5405ba98d7671b41
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 20 Sep 2024 02:45:27 +0200

cmd/install: unify error message formatting

Diffstat:

Mcmd/install.c47++++++++++++++++++++++++++++-------------------
Mtest-cmd/install.t2+-
2 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/cmd/install.c b/cmd/install.c @@ -43,15 +43,22 @@ do_install(char *src, char *dest, bool is_dir) int src_fd = open(src, O_RDONLY); if(src_fd < 0) { - fprintf(stderr, "%s: Failed opening file '%s' for reading: %s\n", argv0, src, strerror(errno)); + fprintf(stderr, + "%s: error: Failed opening file '%s' for reading: %s\n", + argv0, + src, + strerror(errno)); return -1; } struct stat src_stat; if(fstat(src_fd, &src_stat) < 0) { - fprintf( - stderr, "%s: Failed getting status for source '%s': %s\n", argv0, dest, strerror(errno)); + fprintf(stderr, + "%s: error: Failed getting status for source '%s': %s\n", + argv0, + dest, + strerror(errno)); return -1; } @@ -64,7 +71,7 @@ do_install(char *src, char *dest, bool is_dir) if(errno != ENOENT) { fprintf(stderr, - "%s: Failed getting status for destination '%s': %s\n", + "%s: error: Failed getting status for destination '%s': %s\n", argv0, dest, strerror(errno)); @@ -84,7 +91,7 @@ do_install(char *src, char *dest, bool is_dir) if(unlink(dest) < 0) { fprintf(stderr, - "%s: Failed removing existing file at destination '%s': %s\n", + "%s: error: Failed removing existing file at destination '%s': %s\n", argv0, dest, strerror(errno)); @@ -106,7 +113,7 @@ do_install(char *src, char *dest, bool is_dir) if(snprintf(target, PATH_MAX, "%s/%s", dest, src_basename) < 0) { fprintf(stderr, - "%s: Failed joining destination '%s' and source '%s'\n", + "%s: error: Failed joining destination '%s' and source '%s'\n", argv0, dest, src_basename); @@ -122,7 +129,7 @@ do_install(char *src, char *dest, bool is_dir) if(dest_fd < 0) { fprintf(stderr, - "%s: Failed create-opening file '%s' for writing: %s\n", + "%s: error: Failed create-opening file '%s' for writing: %s\n", argv0, dest_path, strerror(errno)); @@ -132,7 +139,7 @@ do_install(char *src, char *dest, bool is_dir) if(auto_file_copy(src_fd, dest_fd, src_stat.st_size, 0) < 0) { fprintf(stderr, - "%s: Error: Failed copying data from '%s' to '%s': %s\n", + "%s: error: Failed copying data from '%s' to '%s': %s\n", argv0, src, dest_path, @@ -146,7 +153,7 @@ do_install(char *src, char *dest, bool is_dir) if(fchown(dest_fd, user, group) < 0) { fprintf(stderr, - "%s: Error: Failed changing ownership of '%s': %s\n", + "%s: error: Failed changing ownership of '%s': %s\n", argv0, dest_path, strerror(errno)); @@ -161,7 +168,7 @@ do_install(char *src, char *dest, bool is_dir) if(futimens(dest_fd, src_times) != 0) { fprintf(stderr, - "%s: Error while setting access/modification times on '%s': %s\n", + "%s: error: Failed setting access/modification times on '%s': %s\n", argv0, dest_path, strerror(errno)); @@ -171,13 +178,13 @@ do_install(char *src, char *dest, bool is_dir) if(close(src_fd) < 0) { - fprintf(stderr, "%s: Error closing '%s'\n", argv0, src); + fprintf(stderr, "%s: error: Failed closing '%s'\n", argv0, src); return -1; } if(close(dest_fd) < 0) { - fprintf(stderr, "%s: Error closing '%s'\n", argv0, dest_path); + fprintf(stderr, "%s: error: Failed closing '%s'\n", argv0, dest_path); return -1; } @@ -263,16 +270,16 @@ main(int argc, char *argv[]) mode = new_mode(optarg, 0755, &errstr); if(errstr != NULL) { - fprintf(stderr, "install: Failed parsing mode '%s': %s\n", optarg, errstr); + fprintf(stderr, "install: error: Failed parsing mode '%s': %s\n", optarg, errstr); return 1; } break; case ':': - fprintf(stderr, "install: Missing operand for option: '-%c'\n", optopt); + fprintf(stderr, "install: error: Missing operand for option: '-%c'\n", optopt); usage(); return 1; case '?': - fprintf(stderr, "install: Unknown option '-%c'\n", optopt); + fprintf(stderr, "install: error: Unknown option '-%c'\n", optopt); usage(); return 1; } @@ -296,7 +303,7 @@ main(int argc, char *argv[]) if(chown(dest, user, group) < 0) { fprintf(stderr, - "%s: Error: Failed changing ownership of '%s': %s\n", + "%s: error: Failed changing ownership of '%s': %s\n", argv0, dest, strerror(errno)); @@ -315,8 +322,10 @@ main(int argc, char *argv[]) { if(argc != 1) { - fprintf( - stderr, "%s: Option -T passed, expected exactly 1 source operand, got %d\n", argv0, argc); + fprintf(stderr, + "%s: error: Option -T passed, expected exactly 1 source operand, got %d\n", + argv0, + argc); return 1; } @@ -324,7 +333,7 @@ main(int argc, char *argv[]) } else if(argc < 1) { - fprintf(stderr, "%s: Expected at least 1 source operand\n", argv0); + fprintf(stderr, "%s: error: Expected at least 1 source operand\n", argv0); return 1; } diff --git a/test-cmd/install.t b/test-cmd/install.t @@ -78,7 +78,7 @@ install -T $ test -e dest_T $ rm dest_T $ install -T src_T src2_T bogus_T - install: Option -T passed, expected exactly 1 source operand, got 2 + install: error: Option -T passed, expected exactly 1 source operand, got 2 [1] $ test -e src_T $ test ! -e src2_T