summaryrefslogtreecommitdiffstats
path: root/src/include/getopt.h
diff options
context:
space:
mode:
authorMichael Brown2006-12-19 17:27:15 +0100
committerMichael Brown2006-12-19 17:27:15 +0100
commit70d20c4e7a156e3161b2578d3b048ae45f23f02a (patch)
tree74b001441cfbfd11632fa1f75362bbe822797398 /src/include/getopt.h
parentUse current attributes when erasing. (diff)
downloadipxe-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/include/getopt.h')
-rw-r--r--src/include/getopt.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/include/getopt.h b/src/include/getopt.h
index 8bf0d331..2505223e 100644
--- a/src/include/getopt.h
+++ b/src/include/getopt.h
@@ -49,9 +49,9 @@ struct option {
extern char *optarg;
extern int optind;
+extern int nextchar;
extern int optopt;
-extern void reset_getopt();
extern int getopt_long ( int argc, char * const argv[], const char *optstring,
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 );
}
+/**
+ * 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 */