From: Jens Axboe Date: Tue, 18 Oct 2011 11:26:01 +0000 (+0200) Subject: Fix klibc getopt_long_only() for optional arguments X-Git-Tag: fio-1.99.9~2 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=9f170691560bacdcd8cef6296d14fc0a8467a9dd;ds=sidebyside Fix klibc getopt_long_only() for optional arguments Signed-off-by: Jens Axboe --- diff --git a/lib/getopt_long.c b/lib/getopt_long.c index 6e8abc06..70894e32 100644 --- a/lib/getopt_long.c +++ b/lib/getopt_long.c @@ -126,7 +126,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 {