DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] Found a bug related to getopt() in eal/bsd module
@ 2015-10-13  8:54 Tiwei Bie
  2015-10-13  8:54 ` [dpdk-dev] [PATCH] eal/bsd: reinitialize optind and optreset to 1 Tiwei Bie
  0 siblings, 1 reply; 9+ messages in thread
From: Tiwei Bie @ 2015-10-13  8:54 UTC (permalink / raw)
  To: dev

I found a bug when trying to make my DPDK application work on FreeBSD.
The variable optind must be reinitialized to 1 on FreeBSD to skip over
argv[0]. Because getopt() on FreeBSD will return -1 when it meets an
argument which doesn't start with '-'. This behaviour is implemented
by the 13-17 lines:

01 /*
02  * getopt --
03  *	Parse argc/argv argument vector.
04  */
05 int
06 getopt(int nargc, char * const nargv[], const char *ostr)
07 {
08 	static char *place = EMSG;		/* option letter processing */
09 	char *oli;				/* option letter list index */
10
11 	if (optreset || *place == 0) {		/* update scanning pointer */
12 		optreset = 0;
13 		place = nargv[optind];
14 		if (optind >= nargc || *place++ != '-') {
15 			/* Argument is absent or is not an option */
16 			place = EMSG;
17 			return (-1);
18 		}
19 		......
20 	}
21 	......
22 }

The variable optreset is also provided on FreeBSD to indicate the
additional set of calls to getopt(). So, also reinitialize it to 1.

References:

1. https://svnweb.freebsd.org/base/head/lib/libc/stdlib/getopt.c?view=markup#l70
2. https://www.freebsd.org/cgi/man.cgi?query=getopt&apropos=0&sektion=3&manpath=FreeBSD+11-current&arch=default&format=html

Tiwei Bie (1):
  eal/bsd: reinitialize optind and optreset to 1

 lib/librte_eal/bsdapp/eal/eal.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

-- 
2.6.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-10-15  1:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-13  8:54 [dpdk-dev] [PATCH] Found a bug related to getopt() in eal/bsd module Tiwei Bie
2015-10-13  8:54 ` [dpdk-dev] [PATCH] eal/bsd: reinitialize optind and optreset to 1 Tiwei Bie
2015-10-13 14:58   ` Bruce Richardson
2015-10-13 17:14   ` Don Provan
     [not found]     ` <20151014022843.GA26774@dell>
2015-10-14  9:31       ` Bruce Richardson
2015-10-14 10:19         ` Tiwei Bie
2015-10-14 11:28           ` Tiwei Bie
2015-10-14 17:54             ` Don Provan
2015-10-15  1:40               ` Tiwei Bie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).