MCPcopy Create free account
hub / github.com/coreboot/coreboot / getopt_internal

Function getopt_internal

payloads/libpayload/libc/getopt_long.c:268–453  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

266 * Parse argc/argv argument vector. Called by user level routines.
267 */
268static int
269getopt_internal(int nargc, char * const *nargv, const char *options,
270 const struct option *long_options, int *idx, int flags)
271{
272 char *oli; /* option letter list index */
273 int optchar, short_too;
274
275 if (options == NULL)
276 return (-1);
277
278 /*
279 * Disable GNU extensions if posixly_correct is set or options
280 * string begins with a '+'.
281 */
282 if (posixly_correct || *options == '+')
283 flags &= ~FLAG_PERMUTE;
284 else if (*options == '-')
285 flags |= FLAG_ALLARGS;
286 if (*options == '+' || *options == '-')
287 options++;
288
289 /*
290 * XXX Some GNU programs (like cvs) set optind to 0 instead of
291 * XXX using optreset. Work around this braindamage.
292 */
293 if (optind == 0)
294 optind = optreset = 1;
295
296 optarg = NULL;
297 if (optreset)
298 nonopt_start = nonopt_end = -1;
299start:
300 if (optreset || !*place) { /* update scanning pointer */
301 optreset = 0;
302 if (optind >= nargc) { /* end of argument vector */
303 place = EMSG;
304 if (nonopt_end != -1) {
305 /* do permutation, if we have to */
306 permute_args(nonopt_start, nonopt_end,
307 optind, nargv);
308 optind -= nonopt_end - nonopt_start;
309 }
310 else if (nonopt_start != -1) {
311 /*
312 * If we skipped non-options, set optind
313 * to the first of them.
314 */
315 optind = nonopt_start;
316 }
317 nonopt_start = nonopt_end = -1;
318 return (-1);
319 }
320 if (*(place = nargv[optind]) != '-' ||
321 (place[1] == '\0' && strchr(options, '-') == NULL)) {
322 place = EMSG; /* found non-option */
323 if (flags & FLAG_ALLARGS) {
324 /*
325 * GNU extension:

Callers 3

getoptFunction · 0.85
getopt_longFunction · 0.85
getopt_long_onlyFunction · 0.85

Calls 3

permute_argsFunction · 0.85
parse_long_optionsFunction · 0.85
strchrFunction · 0.70

Tested by

no test coverage detected