summaryrefslogtreecommitdiffstats
path: root/misc-utils/getopt.c
diff options
context:
space:
mode:
authorKarel Zak2014-12-09 12:21:33 +0100
committerKarel Zak2014-12-09 12:21:33 +0100
commit4b4e1b10f387760aba8a7975222453a568d65771 (patch)
tree3b9f703677a9fad5bfb5a913b7d63323fbb98ad3 /misc-utils/getopt.c
parentgetopt: rename function to keep code readable (diff)
downloadkernel-qcow2-util-linux-4b4e1b10f387760aba8a7975222453a568d65771.tar.gz
kernel-qcow2-util-linux-4b4e1b10f387760aba8a7975222453a568d65771.tar.xz
kernel-qcow2-util-linux-4b4e1b10f387760aba8a7975222453a568d65771.zip
getopt: cleanup add_log_options()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/getopt.c')
-rw-r--r--misc-utils/getopt.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/misc-utils/getopt.c b/misc-utils/getopt.c
index 644d552c9..197bae709 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"));