diff options
author | Michael Brown | 2006-12-19 17:27:15 +0100 |
---|---|---|
committer | Michael Brown | 2006-12-19 17:27:15 +0100 |
commit | 70d20c4e7a156e3161b2578d3b048ae45f23f02a (patch) | |
tree | 74b001441cfbfd11632fa1f75362bbe822797398 /src/core/getopt.c | |
parent | Use current attributes when erasing. (diff) | |
download | ipxe-70d20c4e7a156e3161b2578d3b048ae45f23f02a.tar.gz ipxe-70d20c4e7a156e3161b2578d3b048ae45f23f02a.tar.xz ipxe-70d20c4e7a156e3161b2578d3b048ae45f23f02a.zip |
Use common symbols to avoid dragging in getopt.o unless a getopt-using
command is linked in.
Diffstat (limited to 'src/core/getopt.c')
-rw-r--r-- | src/core/getopt.c | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/src/core/getopt.c b/src/core/getopt.c index df275539..4e839cab 100644 --- a/src/core/getopt.c +++ b/src/core/getopt.c @@ -41,14 +41,14 @@ char *optarg; * 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. */ -int optind = 1; +int optind; /** * Current option character index * * This is an index into the current element of argv[]. */ -static int nextchar = 0; +int nextchar; /** * Unrecognised option @@ -59,22 +59,6 @@ static int nextchar = 0; 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 * * @v argc Argument count @@ -231,6 +215,9 @@ static int match_short_option ( int argc, char * const argv[], * @ret longindex Index of long option (or NULL) * @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, const struct option *longopts, int *longindex ) { |