logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 491288e1bc366768eefc32ac524e2e7acfdf9111
parent edf6bf7701c82730dca390eace7fa92dfd8f0df7
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 20 Sep 2024 03:11:06 +0200

cmd/mknod: unify error message formatting

Diffstat:

Mcmd/mknod.c27++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/cmd/mknod.c b/cmd/mknod.c @@ -32,13 +32,13 @@ strtodev(char *arg) long dev = strtol(arg, &endptr, 0); if(errno != 0) { - fprintf(stderr, "mknod: Failed parsing '%s' into a number: %s\n", arg, strerror(errno)); + fprintf(stderr, "mknod: error: Failed parsing '%s' into a number: %s\n", arg, strerror(errno)); exit(1); } if(endptr != NULL && endptr[0] != 0) { fprintf(stderr, - "mknod: Extraneous characters in '%s' while parsing it as a number: '%s'\n", + "mknod: error: Extraneous characters in '%s' while parsing it as a number: '%s'\n", arg, endptr); exit(1); @@ -63,16 +63,16 @@ main(int argc, char *argv[]) mode = new_mode(optarg, 0666, &errstr); if(errstr != NULL) { - fprintf(stderr, "mknod: Failed parsing mode '%s': %s\n", optarg, errstr); + fprintf(stderr, "mknod: error: Failed parsing mode '%s': %s\n", optarg, errstr); return 1; } break; case ':': - fprintf(stderr, "mknod: Error: Missing operand for option: '-%c'\n", optopt); + fprintf(stderr, "mknod: error: Missing operand for option: '-%c'\n", optopt); usage(); return 1; case '?': - fprintf(stderr, "mknod: Error: Unrecognised option: '-%c'\n", optopt); + fprintf(stderr, "mknod: error: Unrecognised option: '-%c'\n", optopt); usage(); return 1; default: @@ -87,7 +87,7 @@ main(int argc, char *argv[]) if(argc < 2) { - fprintf(stderr, "mknod: Missing operands\n"); + fprintf(stderr, "mknod: error: Missing operands\n"); usage(); return 1; } @@ -97,7 +97,7 @@ main(int argc, char *argv[]) if(type[0] == 0 || type[1] != 0) { - fprintf(stderr, "mknod: Invalid type '%s'\n", type); + fprintf(stderr, "mknod: error: Invalid type '%s'\n", type); usage(); return 1; } @@ -107,7 +107,7 @@ main(int argc, char *argv[]) { if(mknod(file, mode | S_IFIFO, 0) != 0) { - fprintf(stderr, "mknod: Failed creating FIFO at '%s': %s\n", file, strerror(errno)); + fprintf(stderr, "mknod: error: Failed creating FIFO at '%s': %s\n", file, strerror(errno)); return 1; } } @@ -115,7 +115,8 @@ main(int argc, char *argv[]) { if(argc != 4) { - fprintf(stderr, "mknod: non-FIFO device types requires major minor arguments to be given\n"); + fprintf(stderr, + "mknod: error: non-FIFO device types requires major minor arguments to be given\n"); return 1; } @@ -138,14 +139,18 @@ main(int argc, char *argv[]) type_name = "character-special"; break; default: - fprintf(stderr, "mknod: Invalid type '%c'\n", type[0]); + fprintf(stderr, "mknod: error: Invalid type '%c'\n", type[0]); usage(); return 1; } if(mknod(file, mode, makedev(maj, min)) != 0) { - fprintf(stderr, "mknod: Failed creating %s at '%s': %s\n", type_name, file, strerror(errno)); + fprintf(stderr, + "mknod: error: Failed creating %s at '%s': %s\n", + type_name, + file, + strerror(errno)); return 1; } }