summaryrefslogtreecommitdiffstats
path: root/lib
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 /lib
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 'lib')
-rw-r--r--lib/getopt.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/getopt.c b/lib/getopt.c
index 5c35ee17d9..043ba054a5 100644
--- a/lib/getopt.c
+++ b/lib/getopt.c
@@ -34,12 +34,30 @@ EXPORT_SYMBOL(optarg);
static int optindex = 1; /* option index in the current argv[] element */
static int nonopts = 0; /* number of nonopts found */
-void getopt_reset(void)
+void getopt_context_store(struct getopt_context *gc)
{
+ gc->optind = optind;
+ gc->opterr = opterr;
+ gc->optopt = optopt;
+ gc->optarg = optarg;
+ gc->nonopts = nonopts;
+ gc->optindex = optindex;
+
optind = opterr = optindex = 1;
nonopts = 0;
}
-EXPORT_SYMBOL(getopt_reset);
+EXPORT_SYMBOL(getopt_context_store);
+
+void getopt_context_restore(struct getopt_context *gc)
+{
+ optind = gc->optind;
+ opterr = gc->opterr;
+ optopt = gc->optopt;
+ optarg = gc->optarg;
+ nonopts = gc->nonopts;
+ optindex = gc->optindex;
+}
+EXPORT_SYMBOL(getopt_context_restore);
int getopt(int argc, char *argv[], char *optstring)
{