From f97f93c48dc7a3817e59760ee40c860c02bdfbce Mon Sep 17 00:00:00 2001 From: Tibor Nagy Date: Sun, 28 Oct 2018 19:59:08 +0100 Subject: [PATCH] Handle getopt reinitialization --- src/header/getopt/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/header/getopt/mod.rs b/src/header/getopt/mod.rs index 59bbfc2904..5f580381c7 100644 --- a/src/header/getopt/mod.rs +++ b/src/header/getopt/mod.rs @@ -30,6 +30,12 @@ pub unsafe extern "C" fn getopt_long( // if optarg is not set, we still don't want the previous value leaking optarg = ptr::null_mut(); + // handle reinitialization request + if optind == 0 { + optind = 1; + CURRENT_OPT = ptr::null_mut(); + } + if CURRENT_OPT.is_null() || *CURRENT_OPT == 0 { if optind >= argc { -1