summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-02-25 17:10:57 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2012-02-27 19:53:47 +0100
commitaed0e6ba0396dc34a7b7af8a342b6682d9cd1ed0 (patch)
tree0148e7d1d1353c8ba5b622a3dad7589c14f315fc /include
parent2034ee47b1a0dfb3988cf159094d73c3ec623597 (diff)
downloadbarebox-aed0e6ba0396dc34a7b7af8a342b6682d9cd1ed0.tar.gz
barebox-aed0e6ba0396dc34a7b7af8a342b6682d9cd1ed0.tar.xz
getopt: save and restore context
execute_command is the single point where commands are executed and thus a new getopt context is needed. currently we call getopt_reset here to reset the context. This breaks though when a command tries to run a command itself by calling execute_command or run_command. In this case we have to store the context and restore it afterwards. The same is necessary in builtin_getopt. Currently noone does this so this one shouldn't fix a bug, but merely allows us to do such things later. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include')
-rw-r--r--include/getopt.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/include/getopt.h b/include/getopt.h
index 4f43ac4098..ed55e22fde 100644
--- a/include/getopt.h
+++ b/include/getopt.h
@@ -40,10 +40,20 @@ extern char *optarg;
int getopt(int argc, char *argv[], char *optstring);
+struct getopt_context {
+ int opterr;
+ int optind;
+ int optopt;
+ int nonopts;
+ int optindex;
+ char *optarg;
+};
+
/*
* We do not start a new process for each getopt() run, so we
- * need this function to reset the static variables.
+ * need this function to save and restore the context.
*/
-void getopt_reset(void);
+void getopt_context_store(struct getopt_context *ctx);
+void getopt_context_restore(struct getopt_context *ctx);
#endif /* __GETOPT_H */