about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authordana <dana@dana.is>2021-05-03 18:08:11 -0500
committerdana <dana@dana.is>2021-05-03 18:11:38 -0500
commitc23a0d84b029676832ea0f2eeb0caa8c47d0500d (patch)
tree2d404a5367fb6b02b895a53b017d7aa1ffc0ab6e /Src
parent2da0d8b52fc90ce82891ae161fe6df89111c5e5c (diff)
downloadzsh-c23a0d84b029676832ea0f2eeb0caa8c47d0500d.tar.gz
zsh-c23a0d84b029676832ea0f2eeb0caa8c47d0500d.tar.xz
zsh-c23a0d84b029676832ea0f2eeb0caa8c47d0500d.zip
48614: getopts: Calculate OPTIND according to POSIX_BUILTINS
Diffstat (limited to 'Src')
-rw-r--r--Src/builtin.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index efa20607e..b7ceefd55 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5568,6 +5568,11 @@ bin_getopts(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int fun
     /* check for legality */
     if(opch == ':' || !(p = memchr(optstr, opch, lenoptstr))) {
 	p = "?";
+	/* Keep OPTIND correct if the user doesn't return after the error */
+	if (isset(POSIXBUILTINS)) {
+	    optcind = 0;
+	    zoptind++;
+	}
 	zsfree(zoptarg);
 	setsparam(var, ztrdup(p));
 	if(quiet) {
@@ -5584,6 +5589,11 @@ bin_getopts(UNUSED(char *name), char **argv, UNUSED(Options ops), UNUSED(int fun
     if(p[1] == ':') {
 	if(optcind == lenstr) {
 	    if(!args[zoptind]) {
+		/* Fix OPTIND as above */
+		if (isset(POSIXBUILTINS)) {
+		    optcind = 0;
+		    zoptind++;
+		}
 		zsfree(zoptarg);
 		if(quiet) {
 		    setsparam(var, ztrdup(":"));