Use common symbols to avoid dragging in getopt.o unless a getopt-using
command is linked in.
This commit is contained in:
parent
c1bac56f85
commit
70d20c4e7a
|
@ -36,6 +36,10 @@
|
||||||
static struct command commands[0] __table_start ( commands );
|
static struct command commands[0] __table_start ( commands );
|
||||||
static struct command commands_end[0] __table_end ( commands );
|
static struct command commands_end[0] __table_end ( commands );
|
||||||
|
|
||||||
|
/* Avoid dragging in getopt.o unless a command really uses it */
|
||||||
|
int optind;
|
||||||
|
int nextchar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute command
|
* Execute command
|
||||||
*
|
*
|
||||||
|
|
|
@ -41,14 +41,14 @@ char *optarg;
|
||||||
* This is an index into the argv[] array. When getopt() returns -1,
|
* This is an index into the argv[] array. When getopt() returns -1,
|
||||||
* @c optind is the index to the first element that is not an option.
|
* @c optind is the index to the first element that is not an option.
|
||||||
*/
|
*/
|
||||||
int optind = 1;
|
int optind;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current option character index
|
* Current option character index
|
||||||
*
|
*
|
||||||
* This is an index into the current element of argv[].
|
* This is an index into the current element of argv[].
|
||||||
*/
|
*/
|
||||||
static int nextchar = 0;
|
int nextchar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unrecognised option
|
* Unrecognised option
|
||||||
|
@ -58,22 +58,6 @@ static int nextchar = 0;
|
||||||
*/
|
*/
|
||||||
int optopt;
|
int optopt;
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset getopt() internal state
|
|
||||||
*
|
|
||||||
* Due to a limitation of the POSIX getopt() API, it is necessary to
|
|
||||||
* add a call to reset_getopt() before each set of calls to getopt()
|
|
||||||
* or getopt_long(). This arises because POSIX assumes that each
|
|
||||||
* process will parse command line arguments no more than once; this
|
|
||||||
* assumption is not valid within Etherboot. We work around the
|
|
||||||
* limitation by arranging for execv() to call reset_getopt() before
|
|
||||||
* executing the command.
|
|
||||||
*/
|
|
||||||
void reset_getopt ( void ) {
|
|
||||||
optind = 1;
|
|
||||||
nextchar = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get option argument from argv[] array
|
* Get option argument from argv[] array
|
||||||
*
|
*
|
||||||
|
@ -231,6 +215,9 @@ static int match_short_option ( int argc, char * const argv[],
|
||||||
* @ret longindex Index of long option (or NULL)
|
* @ret longindex Index of long option (or NULL)
|
||||||
* @ret option Option found, or -1 for no more options
|
* @ret option Option found, or -1 for no more options
|
||||||
*
|
*
|
||||||
|
* Note that the caller must arrange for reset_getopt() to be called
|
||||||
|
* before each set of calls to getopt_long(). In Etherboot, this is
|
||||||
|
* done automatically by execv().
|
||||||
*/
|
*/
|
||||||
int getopt_long ( int argc, char * const argv[], const char *optstring,
|
int getopt_long ( int argc, char * const argv[], const char *optstring,
|
||||||
const struct option *longopts, int *longindex ) {
|
const struct option *longopts, int *longindex ) {
|
||||||
|
|
|
@ -49,9 +49,9 @@ struct option {
|
||||||
|
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
extern int optind;
|
extern int optind;
|
||||||
|
extern int nextchar;
|
||||||
extern int optopt;
|
extern int optopt;
|
||||||
|
|
||||||
extern void reset_getopt();
|
|
||||||
extern int getopt_long ( int argc, char * const argv[], const char *optstring,
|
extern int getopt_long ( int argc, char * const argv[], const char *optstring,
|
||||||
const struct option *longopts, int *longindex );
|
const struct option *longopts, int *longindex );
|
||||||
|
|
||||||
|
@ -73,4 +73,20 @@ static inline int getopt ( int argc, char * const argv[],
|
||||||
return getopt_long ( argc, argv, optstring, no_options, NULL );
|
return getopt_long ( argc, argv, optstring, no_options, NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset getopt() internal state
|
||||||
|
*
|
||||||
|
* Due to a limitation of the POSIX getopt() API, it is necessary to
|
||||||
|
* add a call to reset_getopt() before each set of calls to getopt()
|
||||||
|
* or getopt_long(). This arises because POSIX assumes that each
|
||||||
|
* process will parse command line arguments no more than once; this
|
||||||
|
* assumption is not valid within Etherboot. We work around the
|
||||||
|
* limitation by arranging for execv() to call reset_getopt() before
|
||||||
|
* executing the command.
|
||||||
|
*/
|
||||||
|
static inline void reset_getopt ( void ) {
|
||||||
|
optind = 1;
|
||||||
|
nextchar = 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _GETOPT_H */
|
#endif /* _GETOPT_H */
|
||||||
|
|
Reference in New Issue