1 /* SPDX-License-Identifier: BSD-2-Clause
2 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Dieter Baron and Thomas Klausner.
13 * This module provides getopt() and getopt_long().
16 #ifndef _USUAL_GETOPT_H_
17 #define _USUAL_GETOPT_H_
19 #ifndef NEED_USUAL_GETOPT
20 #if !defined(HAVE_GETOPT_H) || !defined(HAVE_GETOPT) || \
21 !defined(HAVE_GETOPT_LONG)
22 #define NEED_USUAL_GETOPT
26 #ifndef NEED_USUAL_GETOPT
28 /* Use system getopt */
29 #ifdef RTE_TOOLCHAIN_GCC
30 #include_next <getopt.h>
35 #else /* NEED_USUAL_GETOPT */
37 /* avoid name collision */
38 #define optarg usual_optarg
39 #define opterr usual_opterr
40 #define optind usual_optind
41 #define optopt usual_optopt
42 #define getopt(a, b, c) usual_getopt(a, b, c)
43 #define getopt_long(a, b, c, d, e) usual_getopt_long(a, b, c, d, e)
46 /** argument to current option, or NULL if it has none */
47 extern const char *optarg;
48 /** Current position in arg string. Starts from 1.
49 * Setting to 0 resets state.
52 /** whether getopt() should print error messages on problems. Default: 1. */
54 /** Option char which caused error */
57 /** long option takes no argument */
59 /** long option requires argument */
60 #define required_argument 1
61 /** long option has optional argument */
62 #define optional_argument 2
64 /** Long option description */
66 /** name of long option */
70 * whether option takes an argument.
71 * One of no_argument, required_argument, and optional_argument.
75 /** if not NULL, set *flag to val when option found */
78 /** if flag not NULL, value to set *flag to; else return value */
83 int getopt(int argc, char *argv[], const char *options);
85 /** Compat: getopt_long */
86 int getopt_long(int argc, char *argv[], const char *options,
87 const struct option *longopts, int *longindex);
89 /** Compat: getopt_long_only */
90 int getopt_long_only(int nargc, char *argv[], const char *options,
91 const struct option *long_options, int *idx);
94 #endif /* NEED_USUAL_GETOPT */
96 #endif /* !_USUAL_GETOPT_H_ */