From 9ca2f35f045b0f1096b9817d55376c24d7b446ed Mon Sep 17 00:00:00 2001 From: Craig Small Date: Tue, 7 Feb 2017 22:37:36 +1100 Subject: [PATCH] kill: a better option parser The previous commit would not work in newlib. Further investigation found a better way of parsing this extra option using optind References: commit 536cea324b121f54744369425332c256aa84a181 --- skill.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/skill.c b/skill.c index 5d233c25..14e5b584 100644 --- a/skill.c +++ b/skill.c @@ -422,7 +422,6 @@ static void __attribute__ ((__noreturn__)) int loop = 1; long pid; int exitvalue = EXIT_SUCCESS; - int optindex; char *sig_option; static const struct option longopts[] = { @@ -447,14 +446,14 @@ static void __attribute__ ((__noreturn__)) signo = SIGTERM; opterr=0; /* suppress errors on -123 */ - while (loop == 1 && (i = getopt_long(argc, argv, "l::Ls:hV", longopts, &optindex)) != -1) + while (loop == 1 && (i = getopt_long(argc, argv, "l::Ls:hV", longopts, NULL)) != -1) switch (i) { case 'l': sig_option = NULL; if (optarg) { sig_option = optarg; - } else if (argv[optindex+1] != NULL && argv[optindex+1][0] != '-') { - sig_option = argv[optindex+1]; + } else if (argv[optind] != NULL && argv[optind][0] != '-') { + sig_option = argv[optind]; } if (sig_option) { char *s;