logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 43095555a518d8245c42efb53140438f96a35a06
parent fa7b0128536ce7a6fbe1f5899bee44ff5fe10ec4
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 20 Sep 2024 03:22:18 +0200

cmd/nice: unify error message formatting

Diffstat:

Mcmd/nice.c20+++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/cmd/nice.c b/cmd/nice.c @@ -12,6 +12,8 @@ #include <string.h> // strerror #include <unistd.h> // getopt, nice +const char *argv0 = "nice"; + static void usage(void) { @@ -37,18 +39,21 @@ main(int argc, char *argv[]) if(endptr && *endptr != 0) errno = EINVAL; if(errno != 0) { - fprintf( - stderr, "nice: Error: Failed parsing '%s' as a number: %s\n", optarg, strerror(errno)); + fprintf(stderr, + "%s: error: Failed parsing '%s' as a number: %s\n", + argv0, + optarg, + strerror(errno)); usage(); return 125; } break; case ':': - fprintf(stderr, "nice: Error: Missing operand for option: '-%c'\n", optopt); + fprintf(stderr, "%s: error: Missing operand for option: '-%c'\n", argv0, optopt); usage(); return 125; case '?': - fprintf(stderr, "nice: Error: Unrecognised option: '-%c'\n", optopt); + fprintf(stderr, "%s: error: Unrecognised option: '-%c'\n", argv0, optopt); usage(); return 125; default: @@ -69,11 +74,12 @@ main(int argc, char *argv[]) case 0: break; case EPERM: - fprintf(stderr, "nice: Warning: Failed setting nice to %ld: %s\n", incr, strerror(errno)); + fprintf( + stderr, "%s: warning: Failed setting nice to %ld: %s\n", argv0, incr, strerror(errno)); errno = 0; break; default: - fprintf(stderr, "nice: Error: Failed setting nice to %ld: %s\n", incr, strerror(errno)); + fprintf(stderr, "%s: error: Failed setting nice to %ld: %s\n", argv0, incr, strerror(errno)); return 125; } } @@ -82,7 +88,7 @@ main(int argc, char *argv[]) assert(errno == 0); if(execvp(argv[0], argv) < 0) { - fprintf(stderr, "nice: execvp(\"%s\", ...): %s\n", argv[0], strerror(errno)); + fprintf(stderr, "%s: error: Failed executing '%s': %s\n", argv0, argv[0], strerror(errno)); return (errno == ENOENT) ? 127 : 126; }