X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=lib%2Fgetopt_long.c;h=11d879ad2bfe70f4ab76d06bcc8aad20d36c4c16;hp=3d80627f5395c6bba4d5d28ac73170c46290e198;hb=a1f871c72971efe84cd42670d5df4c4dc56dbd3f;hpb=bf2e821a55d8aa3de1cda7288a0e22883110fdc6 diff --git a/lib/getopt_long.c b/lib/getopt_long.c index 3d80627f..11d879ad 100644 --- a/lib/getopt_long.c +++ b/lib/getopt_long.c @@ -6,15 +6,19 @@ * - Option reordering is not supported * - -W foo is not supported * - First optstring character "-" not supported. + * + * This file was imported from the klibc library from hpa */ #include #include #include -#include -char *optarg; -int optind, opterr, optopt; +#include "getopt.h" + +char *optarg = NULL; +int optind = 0, opterr = 0, optopt = 0; + static struct getopt_private_state { const char *optptr; const char *last_optstring; @@ -42,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 @@ -123,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 {