From 16ba0b39f3b2f27d9fbca0bd0ea6d85ae8a501a5 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Sat, 16 May 2020 01:47:10 +0430 Subject: [PATCH] LibCore: Reset getopt's state when starting parse() This way, a program can use ArgsParser multiple times, potentially with multiple different options. --- Libraries/LibCore/ArgsParser.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Libraries/LibCore/ArgsParser.cpp b/Libraries/LibCore/ArgsParser.cpp index 18e42011f17..3ebd6c2e53f 100644 --- a/Libraries/LibCore/ArgsParser.cpp +++ b/Libraries/LibCore/ArgsParser.cpp @@ -49,6 +49,8 @@ void ArgsParser::parse(int argc, char** argv) int index_of_found_long_option = -1; + optind = 0; + for (size_t i = 0; i < m_options.size(); i++) { auto& opt = m_options[i]; if (opt.long_name) {