6 * Parse command-line options
10 FILE_LICENCE ( GPL2_OR_LATER
);
14 enum getopt_argument_requirement
{
15 /** Option does not take an argument */
17 /** Option requires an argument */
18 required_argument
= 1,
19 /** Option may have an argument */
20 optional_argument
= 2,
23 /** A long option, as used for getopt_long() */
25 /** Long name of this option */
27 /** Option takes an argument
29 * Must be one of @c no_argument, @c required_argument, or @c
33 /** Location into which to store @c val, or NULL.
35 * See the description for @c val for more details.
40 * If @c flag is NULL, then this is the value that will be
41 * returned by getopt_long() when this option is found, and
42 * should therefore be set to the equivalent short option
45 * If @c flag is non-NULL, then this value will be written to
46 * the location pointed to by @flag, and getopt_long() will
57 extern int getopt_long ( int argc
, char * const argv
[], const char *optstring
,
58 const struct option
*longopts
, int *longindex
);
61 * Parse command-line options
63 * @v argv Argument count
64 * @v argv Argument list
65 * @v optstring Option specification string
66 * @ret option Option found, or -1 for no more options
68 * See getopt_long() for full details.
70 static inline int getopt ( int argc
, char * const argv
[],
71 const char *optstring
) {
72 static const struct option no_options
[] = {
75 return getopt_long ( argc
, argv
, optstring
, no_options
, NULL
);
79 * Reset getopt() internal state
81 * Due to a limitation of the POSIX getopt() API, it is necessary to
82 * add a call to reset_getopt() before each set of calls to getopt()
83 * or getopt_long(). This arises because POSIX assumes that each
84 * process will parse command line arguments no more than once; this
85 * assumption is not valid within Etherboot. We work around the
86 * limitation by arranging for execv() to call reset_getopt() before
87 * executing the command.
89 static inline void reset_getopt ( void ) {
94 #endif /* _GETOPT_H */