[dpdk-dev] eal/bsd: reinitialize optind and optreset to 1
Commit Message
The variable optind must be reinitialized to 1 in order to skip over
argv[0] on FreeBSD. Because getopt() on FreeBSD will return -1 when
it meets an argument which doesn't start with '-'.
The variable optreset is provided on FreeBSD to indicate the additional
set of calls to getopt(). So, also reinitialize it to 1.
Signed-off-by: Tiwei Bie <btw@mail.ustc.edu.cn>
---
lib/librte_eal/bsdapp/eal/eal.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
Comments
On Tue, Oct 13, 2015 at 04:54:06PM +0800, Tiwei Bie wrote:
> The variable optind must be reinitialized to 1 in order to skip over
> argv[0] on FreeBSD. Because getopt() on FreeBSD will return -1 when
> it meets an argument which doesn't start with '-'.
>
> The variable optreset is provided on FreeBSD to indicate the additional
> set of calls to getopt(). So, also reinitialize it to 1.
>
> Signed-off-by: Tiwei Bie <btw@mail.ustc.edu.cn>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
@@ -334,7 +334,8 @@ eal_log_level_parse(int argc, char **argv)
break;
}
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
+ optreset = 1;
}
/* Parse the argument given in the command line of the application */
@@ -403,7 +404,8 @@ eal_parse_args(int argc, char **argv)
if (optind >= 0)
argv[optind-1] = prgname;
ret = optind-1;
- optind = 0; /* reset getopt lib */
+ optind = 1; /* reset getopt lib */
+ optreset = 1;
return ret;
}