|
@@ -41,14 +41,14 @@ char *optarg;
|
41
|
41
|
* This is an index into the argv[] array. When getopt() returns -1,
|
42
|
42
|
* @c optind is the index to the first element that is not an option.
|
43
|
43
|
*/
|
44
|
|
-int optind = 1;
|
|
44
|
+int optind;
|
45
|
45
|
|
46
|
46
|
/**
|
47
|
47
|
* Current option character index
|
48
|
48
|
*
|
49
|
49
|
* This is an index into the current element of argv[].
|
50
|
50
|
*/
|
51
|
|
-static int nextchar = 0;
|
|
51
|
+int nextchar;
|
52
|
52
|
|
53
|
53
|
/**
|
54
|
54
|
* Unrecognised option
|
|
@@ -58,22 +58,6 @@ static int nextchar = 0;
|
58
|
58
|
*/
|
59
|
59
|
int optopt;
|
60
|
60
|
|
61
|
|
-/**
|
62
|
|
- * Reset getopt() internal state
|
63
|
|
- *
|
64
|
|
- * Due to a limitation of the POSIX getopt() API, it is necessary to
|
65
|
|
- * add a call to reset_getopt() before each set of calls to getopt()
|
66
|
|
- * or getopt_long(). This arises because POSIX assumes that each
|
67
|
|
- * process will parse command line arguments no more than once; this
|
68
|
|
- * assumption is not valid within Etherboot. We work around the
|
69
|
|
- * limitation by arranging for execv() to call reset_getopt() before
|
70
|
|
- * executing the command.
|
71
|
|
- */
|
72
|
|
-void reset_getopt ( void ) {
|
73
|
|
- optind = 1;
|
74
|
|
- nextchar = 0;
|
75
|
|
-}
|
76
|
|
-
|
77
|
61
|
/**
|
78
|
62
|
* Get option argument from argv[] array
|
79
|
63
|
*
|
|
@@ -231,6 +215,9 @@ static int match_short_option ( int argc, char * const argv[],
|
231
|
215
|
* @ret longindex Index of long option (or NULL)
|
232
|
216
|
* @ret option Option found, or -1 for no more options
|
233
|
217
|
*
|
|
218
|
+ * Note that the caller must arrange for reset_getopt() to be called
|
|
219
|
+ * before each set of calls to getopt_long(). In Etherboot, this is
|
|
220
|
+ * done automatically by execv().
|
234
|
221
|
*/
|
235
|
222
|
int getopt_long ( int argc, char * const argv[], const char *optstring,
|
236
|
223
|
const struct option *longopts, int *longindex ) {
|