summary refs log tree commit diff
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2014-10-07 22:24:42 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2014-10-07 22:24:42 +0800
commitf20dcdd0948d7ebb7d462a0288ea218468ad4f6c (patch)
treefc567086d638a8e16bff87dd8330d288bf06a530
parent[BUILTIN] Return without arguments in a trap should use status outside traps (diff)
downloaddash-f20dcdd0948d7ebb7d462a0288ea218468ad4f6c.tar.gz
dash-f20dcdd0948d7ebb7d462a0288ea218468ad4f6c.zip
[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@gondor.apana.org.au>
Diffstat (limited to '')
-rw-r--r--ChangeLog4
-rw-r--r--src/var.c5
2 files changed, 7 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index aa230ab..b990628 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2014-10-07  Herbert Xu <herbert@gondor.apana.org.au>
+
+	* Use setvareq to set OPTIND initially.
+
 2014-10-06  Herbert Xu <herbert@gondor.apana.org.au>
 
 	* Exit without arguments in a trap should use status outside traps.
diff --git a/src/var.c b/src/var.c
index fa24854..cc6f7f2 100644
--- a/src/var.c
+++ b/src/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);
/span>Implement graceful shutdownJune McEnroe 2019-10-26Require PASS before USERJune McEnroe Prevent creating a ring consumer without authentication. 2019-10-26Track channel topicsJune McEnroe 2019-10-26Set AWAY when no clients are connectedJune McEnroe 2019-10-26Add flags to request TOPIC and NAMES on client connectJune McEnroe 2019-10-26OopsJune McEnroe 2019-10-26Disconnect client on unknown commandJune McEnroe During registration, no other commands should be sent. Afterwards, only intercepted commands will get parsed. 2019-10-26Allow reading sensitive information from filesJune McEnroe 2019-10-26Add rc scriptJune McEnroe 2019-10-25Add install and uninstall targetsJune McEnroe 2019-10-25Expand documentationJune McEnroe 2019-10-25Add AGPLv3 notice on client registrationJune McEnroe OwO 2019-10-25Rename project pounceJune McEnroe