From: Karel Zak Date: Tue, 9 Dec 2014 11:21:33 +0000 (+0100) Subject: getopt: cleanup add_log_options() X-Git-Tag: v2.26-rc1~137 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b4e1b10f387760aba8a7975222453a568d65771;p=thirdparty%2Futil-linux.git getopt: cleanup add_log_options() Signed-off-by: Karel Zak --- diff --git a/misc-utils/getopt.c b/misc-utils/getopt.c index 644d552c90..197bae7099 100644 --- a/misc-utils/getopt.c +++ b/misc-utils/getopt.c @@ -266,18 +266,21 @@ static void add_long_options(struct getopt_control *ctl, char *options) { int arg_opt; char *tokptr = strtok(options, ", \t\n"); + while (tokptr) { + size_t len = strlen(tokptr); + arg_opt = no_argument; - if (strlen(tokptr) > 0) { - if (tokptr[strlen(tokptr) - 1] == ':') { - if (tokptr[strlen(tokptr) - 2] == ':') { - tokptr[strlen(tokptr) - 2] = '\0'; + if (len > 0) { + if (tokptr[len - 1] == ':') { + if (tokptr[len - 2] == ':') { + tokptr[len - 2] = '\0'; arg_opt = optional_argument; } else { - tokptr[strlen(tokptr) - 1] = '\0'; + tokptr[len - 1] = '\0'; arg_opt = required_argument; } - if (strlen(tokptr) == 0) + if (!*tokptr) parse_error(_ ("empty long option after " "-l or --long argument"));