MCPcopy Create free account
hub / github.com/F-Stack/f-stack / getopt_internal

Function getopt_internal

dpdk/lib/eal/windows/getopt.c:238–430  ·  view source on GitHub ↗

* getopt_internal -- * Parse argc/argv argument vector. Called by user level routines. */

Source from the content-addressed store, hash-verified

236 * Parse argc/argv argument vector. Called by user level routines.
237 */
238static int
239getopt_internal(int nargc, char **nargv, const char *options,
240 const struct option *long_options, int *idx, int flags)
241{
242 char *oli; /* option letter list index */
243 int optchar, short_too;
244 static int posixly_correct = -1;
245 size_t len;
246 int optreset = 0;
247
248 if (options == NULL)
249 return (-1);
250
251 /*
252 * Disable GNU extensions if POSIXLY_CORRECT is set or options
253 * string begins with a '+'.
254 */
255 if (posixly_correct == -1) {
256 errno_t err = _wgetenv_s(&len, NULL, 0, L"POSIXLY_CORRECT");
257 posixly_correct = (err == 0) && (len > 0);
258 }
259 if (!posixly_correct || *options == '+')
260 flags &= ~FLAG_PERMUTE;
261 else if (*options == '-')
262 flags |= FLAG_ALLARGS;
263 if (*options == '+' || *options == '-')
264 options++;
265 /*
266 * reset if requested
267 */
268 if (optind == 0)
269 optind = optreset = 1;
270
271 optarg = NULL;
272 if (optreset)
273 nonopt_start = nonopt_end = -1;
274start:
275 if (optreset || !*place) { /* update scanning pointer */
276 optreset = 0;
277 if (optind >= nargc) { /* end of argument vector */
278 place = EMSG;
279 if (nonopt_end != -1) {
280 /* do permutation, if we have to */
281 permute_args(nonopt_start, nonopt_end,
282 optind, nargv);
283 optind -= nonopt_end - nonopt_start;
284 } else if (nonopt_start != -1) {
285 /*
286 * If we skipped non-options, set optind
287 * to the first of them.
288 */
289 optind = nonopt_start;
290 }
291 nonopt_start = nonopt_end = -1;
292 return (-1);
293 }
294 place = nargv[optind];
295 if (*place != '-' ||

Callers 3

getoptFunction · 0.85
getopt_longFunction · 0.85
getopt_long_onlyFunction · 0.85

Calls 3

permute_argsFunction · 0.85
strchrFunction · 0.85
parse_long_optionsFunction · 0.85

Tested by

no test coverage detected