Hi! On Wed, Jan 04, 2023 at 05:59:47PM +0800, Herbert Xu wrote: > On Tue, Jan 03, 2023 at 01:26:19PM +0100, наб wrote: > > > However, I don't think we need to pass the flags to the action > > > function since none of them care about whether it's unset. We > > > just need to pass a pointer to an empty string rather than some > > > bogus pointer. > > This, unsurprisingly, produces the same error, because getoptsreset() > > needs a valid number for OPTIND: > > $ src/dash -c 'unset OPTIND' > > src/dash: 1: unset: Illegal number: > You get the same result with OPTIND="" so I don't see the issue. Which is an unrelated operation, and obviously nonsensical. It's good that it fails. > Am I missing something with respect to POSIX? AFAICT, after trawling through the Issue 8 Draft 2.1, there are no special provisions for unset/OPTIND, like there are for readonly. (See the other branch of this thread, but to summarise: setting LINENO, OLDPWD, OPTARG, OPTIND, or PWD readonly /must/ fail in: (a) readonly xor (b) the builtin that edits it xor (c) on assignment.) This indicates that "unset OPTIND" must behave as-specified, i.e. unset OPTIND and remove it from the environment. In dash, this really only affects OPTIND, since the only other special variable that parses an int is sethistsize(), which explicitly has -- >8 -- if (hist != NULL) { if (hs == NULL || *hs == '\0' || (histsize = atoi(hs)) < 0) histsize = 100; history(hist, &he, H_SETSIZE, histsize); } -- >8 -- which considers HISTSIZE= and unset HISTSIZE to be equivalent; the only other setter function that inspects the new value is for PATH, and working out to the empty string works for that case. We could also pass NULL when unsetting, I guess, since sethistsize() is already equipped for it, if you prefer to not have a flags argument? Best, наб
Attachment:
signature.asc
Description: PGP signature