X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=lib%2Fgetopt_long.c;h=11d879ad2bfe70f4ab76d06bcc8aad20d36c4c16;hp=6e8abc0678d1280f415f9c2d4e20f79778a36982;hb=25c42559e065f5a94a696b7bbefa32426d7b8925;hpb=eb078db384e336c1f2338adfdf8f6594660964d6 diff --git a/lib/getopt_long.c b/lib/getopt_long.c index 6e8abc06..11d879ad 100644 --- a/lib/getopt_long.c +++ b/lib/getopt_long.c @@ -16,8 +16,9 @@ #include "getopt.h" -char *optarg; -int optind, opterr, optopt; +char *optarg = NULL; +int optind = 0, opterr = 0, optopt = 0; + static struct getopt_private_state { const char *optptr; const char *last_optstring; @@ -45,6 +46,8 @@ int getopt_long_only(int argc, char *const *argv, const char *optstring, const char *osptr; int opt; + optarg = NULL; + /* getopt() relies on a number of different global state variables, which can make this really confusing if there is more than one use of getopt() in the same program. This @@ -126,7 +129,16 @@ int getopt_long_only(int argc, char *const *argv, const char *optstring, } else { /* Argument-taking option with non-attached argument */ - if (argv[optind + 1]) { + if (osptr[2] == ':') { + if (argv[optind + 1]) { + optarg = (char *)argv[optind+1]; + optind += 2; + } else { + optarg = NULL; + optind++; + } + return opt; + } else if (argv[optind + 1]) { optarg = (char *)argv[optind+1]; optind += 2; } else {