From 0810ed6572fc2903ed9e9c1e9cb4b01a31c029b9 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Tue, 12 Feb 2019 02:54:03 +0800 Subject: [PATCH] [posix-app] explictly set optind (#3574) This allows another options parser before initializing OpenThread. --- src/posix/platform/system.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/posix/platform/system.c b/src/posix/platform/system.c index fb435a573..298cf1bc6 100644 --- a/src/posix/platform/system.c +++ b/src/posix/platform/system.c @@ -51,6 +51,12 @@ #include "openthread-system.h" +static const struct option kOptions[] = {{"dry-run", no_argument, NULL, 'n'}, + {"radio-version", no_argument, NULL, 0}, + {"help", no_argument, NULL, 'h'}, + {"time-speed", required_argument, NULL, 's'}, + {0, 0, 0, 0}}; + uint64_t gNodeId = 0; static void PrintUsage(const char *aProgramName, FILE *aStream, int aExitCode) @@ -76,17 +82,12 @@ otInstance *otSysInit(int aArgCount, char *aArgVector[]) bool isDryRun = false; bool printRadioVersion = false; + optind = 1; + while (true) { - int index = 0; - int option; - const struct option options[] = {{"dry-run", no_argument, NULL, 'n'}, - {"radio-version", no_argument, NULL, 0}, - {"help", no_argument, NULL, 'h'}, - {"time-speed", required_argument, NULL, 's'}, - {0, 0, 0, 0}}; - - option = getopt_long(aArgCount, aArgVector, "hns:", options, &index); + int index = 0; + int option = getopt_long(aArgCount, aArgVector, "hns:", kOptions, &index); if (option == -1) { @@ -114,7 +115,7 @@ otInstance *otSysInit(int aArgCount, char *aArgVector[]) break; } case 0: - if (!strcmp(options[index].name, "radio-version")) + if (!strcmp(kOptions[index].name, "radio-version")) { printRadioVersion = true; }