logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: a926e30b91a25365f7b16e8e1396f794df1af3f1
parent 3036b591ff1ec69df9ad627f641b100f080ca834
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 20 Sep 2024 04:45:28 +0200

cmd/truncate: unify error message formatting

Diffstat:

Mcmd/truncate.c18++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/cmd/truncate.c b/cmd/truncate.c @@ -48,7 +48,7 @@ main(int argc, char *argv[]) case 'r': if(size_set) { - fprintf(stderr, "truncate: Error: Truncation size can only be set once\n"); + fprintf(stderr, "truncate: error: Truncation size can only be set once\n"); usage(); return 1; } @@ -58,7 +58,7 @@ main(int argc, char *argv[]) case 's': if(size_set) { - fprintf(stderr, "truncate: Error: Truncation size can only be set once\n"); + fprintf(stderr, "truncate: error: Truncation size can only be set once\n"); usage(); return 1; } @@ -70,11 +70,11 @@ main(int argc, char *argv[]) size_set = true; break; case ':': - fprintf(stderr, "truncate: Error: Missing operand for option: '-%c'\n", optopt); + fprintf(stderr, "truncate: error: Missing operand for option: '-%c'\n", optopt); usage(); return 1; case '?': - fprintf(stderr, "truncate: Error: Unrecognised option: '-%c'\n", optopt); + fprintf(stderr, "truncate: error: Unrecognised option: '-%c'\n", optopt); usage(); return 1; default: @@ -90,7 +90,7 @@ main(int argc, char *argv[]) if(!size_set) { fprintf(stderr, - "truncate: Error: target size wasn't set, you need to pass one of -d / -r / -s\n"); + "truncate: error: target size wasn't set, you need to pass one of -d / -r / -s\n"); return 1; } @@ -101,7 +101,7 @@ main(int argc, char *argv[]) if(stat(optarg, &ref_stats) < 0) { fprintf(stderr, - "truncate: Error: Couldn't get status for file '%s': %s\n", + "truncate: error: Couldn't get status for file '%s': %s\n", optarg, strerror(errno)); return 1; @@ -119,7 +119,7 @@ main(int argc, char *argv[]) int fd = open(arg, open_flags); if(fd < 0) { - fprintf(stderr, "truncate: Error: Failed to open '%s': %s\n", arg, strerror(errno)); + fprintf(stderr, "truncate: error: Failed to open '%s': %s\n", arg, strerror(errno)); return 1; } assert(errno == 0); @@ -128,8 +128,10 @@ main(int argc, char *argv[]) if(close(fd) < 0) { - fprintf(stderr, "truncate: Error: Failed closing fd for '%s': %s\n", arg, strerror(errno)); + fprintf(stderr, "truncate: error: Failed closing fd for '%s': %s\n", arg, strerror(errno)); return 1; } } + + return 0; }