[klibc] [klibc:update-dash] [VAR] Use setvareq to set OPTIND initially

klibc-bot for Herbert Xu herbert at gondor.apana.org.au
Thu Jan 24 19:15:21 PST 2019


Commit-ID:  c70ab0138910d5351ca0386e0220e4e0944c439d
Gitweb:     http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=c70ab0138910d5351ca0386e0220e4e0944c439d
Author:     Herbert Xu <herbert at gondor.apana.org.au>
AuthorDate: Tue, 7 Oct 2014 22:24:42 +0800
Committer:  Ben Hutchings <ben at decadent.org.uk>
CommitDate: Fri, 25 Jan 2019 02:57:21 +0000

[klibc] [VAR] Use setvareq to set OPTIND initially

There is no need to setvarint to set the initial value of OPTIND
of one.  This patch switchs to setvareq which also lets us avoid
an unnecessary memory allocation.

Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben at decadent.org.uk>

---
 usr/dash/var.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/usr/dash/var.c b/usr/dash/var.c
index fa248544..cc6f7f2a 100644
--- a/usr/dash/var.c
+++ b/usr/dash/var.c
@@ -80,6 +80,7 @@ const char defifsvar[] = "IFS= \t\n";
 #else
 const char defifs[] = " \t\n";
 #endif
+MKINIT char defoptindvar[] = "OPTIND=1";
 
 int lineno;
 char linenovar[sizeof("LINENO=")+sizeof(int)*CHAR_BIT/3+1] = "LINENO=";
@@ -100,7 +101,7 @@ struct var varinit[] = {
 	{ 0,	VSTRFIXED|VTEXTFIXED,		"PS1=$ ",	0 },
 	{ 0,	VSTRFIXED|VTEXTFIXED,		"PS2=> ",	0 },
 	{ 0,	VSTRFIXED|VTEXTFIXED,		"PS4=+ ",	0 },
-	{ 0,	VSTRFIXED|VTEXTFIXED,		"OPTIND=1",	getoptsreset },
+	{ 0,	VSTRFIXED|VTEXTFIXED,		defoptindvar,	getoptsreset },
 #ifdef WITH_LINENO
 	{ 0,	VSTRFIXED|VTEXTFIXED,		linenovar,	0 },
 #endif
@@ -142,7 +143,7 @@ INIT {
 		}
 	}
 
-	setvarint("OPTIND", 1, 0);
+	setvareq(defoptindvar, VTEXTFIXED);
 
 	fmtstr(ppid + 5, sizeof(ppid) - 5, "%ld", (long) getppid());
 	setvareq(ppid, VTEXTFIXED);


More information about the klibc mailing list