commit 9f7d081a8c593948136742d0b347794e79c9d6a0
parent 1a0d3c18e42088fa0412f6f2245b45beb3c4f691
Author: Benjamin Baier <programmer@netzbasis.de>
Date: Tue, 5 Jan 2021 11:48:10 +0100
make use of getprogname(3)
Diffstat:
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/after.c b/after.c
@@ -10,21 +10,20 @@
#include <string.h>
#include <unistd.h>
-char *progname;
int verbose;
void
-usage(char *progname)
+usage(void)
{
fprintf(stderr, "usage: %s [-h] [-v] [-p pid | -n process_name] -e string\n",
- progname);
+ getprogname());
}
void
debug_print(const char *message)
{
if (verbose == 1)
- fprintf(stderr, "%s: %s\n", progname, message);
+ fprintf(stderr, "%s: %s\n", getprogname(), message);
}
@@ -82,7 +81,6 @@ main(int argc, char *argv[])
struct kinfo_proc **kinfo;
verbose = 0;
- progname = argv[0];
// argument parsing...
while((ch = getopt(argc, argv, "e:hn:p:v")) != -1)
@@ -100,22 +98,22 @@ main(int argc, char *argv[])
verbose = 1;
break;
case 'h':
- usage(progname);
+ usage();
return 0;
default:
- usage(progname);
+ usage();
exit(1);
}
// argument checking...
// show usage if neither a pid nor a pname are given
if (!(pname != NULL || pid != 0)) {
- usage(progname);
+ usage();
exit(1);
}
// show usage if no output string is given
if (cmd == NULL) {
- usage(progname);
+ usage();
exit(1);
}