From cd273e2e8f5b6a29e4ed4b837e39a9f87b6b0df5 Mon Sep 17 00:00:00 2001 From: Ricardo Branco Date: Sun, 5 Jan 2025 15:22:54 +0100 Subject: [PATCH] solaris: Use getopt_long() to print version --- bsd/restartable.c | 1 - solaris/restartable.c | 24 ++++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/bsd/restartable.c b/bsd/restartable.c index cee5156..4638623 100644 --- a/bsd/restartable.c +++ b/bsd/restartable.c @@ -314,7 +314,6 @@ version(void) { int main(int argc, char *argv[]) { int ch; - struct option longopts[] = { {"verbose", no_argument, NULL, 'v'}, {"version", no_argument, NULL, 'V'}, diff --git a/solaris/restartable.c b/solaris/restartable.c index 9194924..d791951 100644 --- a/solaris/restartable.c +++ b/solaris/restartable.c @@ -10,10 +10,13 @@ #include #include #include +#include #include #define _KERNEL #include +#define VERSION "2.3.4" + static int verbose; static int @@ -146,31 +149,44 @@ print_all(void) { } static void -usage(void) -{ +usage(void) { fprintf(stderr, "Usage: %s [-v]\n", getprogname()); exit(1); } +static void +version(void) { + printf("%s %s\n", getprogname(), VERSION); +} + int main(int argc, char *argv[]) { int ch; + struct option longopts[] = { + {"verbose", no_argument, NULL, 'v'}, + {"version", no_argument, NULL, 'V'}, + }; - while ((ch = getopt(argc, argv, "v")) != -1) { + while ((ch = getopt_long(argc, argv, "v", longopts, NULL)) != -1) { switch (ch) { case 'v': verbose = 1; break; + case 'V': + version(); + return (0); default: usage(); } } + argc -= optind; + argv += optind; if (argc != 0) usage(); printf("PID\tPPID\tUID\tUser\tCommand\n"); print_all(); - return 0; + return (0); }