popt/backport-Consider-POPT_CONTEXT_KEEP_FIRST-during-reset.patch

39 lines
1.2 KiB
Diff

From cd32d1c7da8265a06491d72190c649496ae2f489 Mon Sep 17 00:00:00 2001
From: Tobias Stoeckmann <tobias@stoeckmann.org>
Date: Sun, 16 Aug 2020 20:39:20 +0200
Subject: [PATCH] Consider POPT_CONTEXT_KEEP_FIRST during reset.
If context is created with POPT_CONTEXT_KEEP_FIRST flag, then the
first argv entry is parsed as well (argv[0] is normally the program
name).
Calling poptResetContext should reset the context exactly back into
the state in wich it was after poptGetContext.
Unfortunately the "next" value is always set to 1, i.e. pointing
towards argv[1]. Consider POPT_CONTEXT_KEEP_FIRST. If it is set,
point to argv[0] just like poptGetContext does.
---
src/popt.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/popt.c b/src/popt.c
index c08b3c9..b7d9478 100644
--- a/src/popt.c
+++ b/src/popt.c
@@ -210,7 +210,10 @@ void poptResetContext(poptContext con)
con->os->currAlias = NULL;
con->os->nextCharArg = NULL;
con->os->nextArg = _free(con->os->nextArg);
- con->os->next = 1; /* skip argv[0] */
+ if (!(con->flags & POPT_CONTEXT_KEEP_FIRST))
+ con->os->next = 1; /* skip argv[0] */
+ else
+ con->os->next = 0;
con->numLeftovers = 0;
con->nextLeftover = 0;
--
2.27.0