diff options
author | dana <dana@dana.is> | 2021-05-03 18:08:11 -0500 |
---|---|---|
committer | dana <dana@dana.is> | 2021-05-03 18:11:38 -0500 |
commit | c23a0d84b029676832ea0f2eeb0caa8c47d0500d (patch) | |
tree | 2d404a5367fb6b02b895a53b017d7aa1ffc0ab6e /Src | |
parent | 2da0d8b52fc90ce82891ae161fe6df89111c5e5c (diff) | |
download | zsh-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.c | 10 |
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(":")); |