aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-10-26 17:34:26 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2016-10-26 17:34:26 +0200
commit35c2a136cd74402932d94ca69bd5f69ca900d83f (patch)
treeab4d192523175b215f853f0077603d95d718b12d /shell
parent3df1410a00a7a57f3a43373c00cdea2031d7d70c (diff)
downloadbusybox-w32-35c2a136cd74402932d94ca69bd5f69ca900d83f.tar.gz
busybox-w32-35c2a136cd74402932d94ca69bd5f69ca900d83f.tar.bz2
busybox-w32-35c2a136cd74402932d94ca69bd5f69ca900d83f.zip
ash: use shellparam.optind/optoff in getopts() directly, not through pointers
This is a preparatory patch for next change Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 21373b65a..3effa0c81 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -10554,7 +10554,7 @@ change_random(const char *value)
10554 10554
10555#if ENABLE_ASH_GETOPTS 10555#if ENABLE_ASH_GETOPTS
10556static int 10556static int
10557getopts(char *optstr, char *optvar, char **optfirst, int *param_optind, int *optoff) 10557getopts(char *optstr, char *optvar, char **optfirst)
10558{ 10558{
10559 char *p, *q; 10559 char *p, *q;
10560 char c = '?'; 10560 char c = '?';
@@ -10565,12 +10565,15 @@ getopts(char *optstr, char *optvar, char **optfirst, int *param_optind, int *opt
10565 10565
10566 sbuf[1] = '\0'; 10566 sbuf[1] = '\0';
10567 10567
10568 optnext = optfirst + *param_optind - 1; 10568 optnext = optfirst + shellparam.optind - 1;
10569 10569
10570 if (*param_optind <= 1 || *optoff < 0 || (int)strlen(optnext[-1]) < *optoff) 10570 if (shellparam.optind <= 1
10571 || shellparam.optoff < 0
10572 || (int)strlen(optnext[-1]) < shellparam.optoff
10573 ) {
10571 p = NULL; 10574 p = NULL;
10572 else 10575 } else
10573 p = optnext[-1] + *optoff; 10576 p = optnext[-1] + shellparam.optoff;
10574 if (p == NULL || *p == '\0') { 10577 if (p == NULL || *p == '\0') {
10575 /* Current word is done, advance */ 10578 /* Current word is done, advance */
10576 p = *optnext; 10579 p = *optnext;
@@ -10625,15 +10628,15 @@ getopts(char *optstr, char *optvar, char **optfirst, int *param_optind, int *opt
10625 } else 10628 } else
10626 err |= setvarsafe("OPTARG", nullstr, 0); 10629 err |= setvarsafe("OPTARG", nullstr, 0);
10627 out: 10630 out:
10628 *optoff = p ? p - *(optnext - 1) : -1; 10631 shellparam.optoff = p ? p - *(optnext - 1) : -1;
10629 *param_optind = optnext - optfirst + 1; 10632 shellparam.optind = optnext - optfirst + 1;
10630 err |= setvarsafe("OPTIND", itoa(*param_optind), VNOFUNC); 10633 err |= setvarsafe("OPTIND", itoa(shellparam.optind), VNOFUNC);
10631 sbuf[0] = c; 10634 sbuf[0] = c;
10632 /*sbuf[1] = '\0'; - already is */ 10635 /*sbuf[1] = '\0'; - already is */
10633 err |= setvarsafe(optvar, sbuf, 0); 10636 err |= setvarsafe(optvar, sbuf, 0);
10634 if (err) { 10637 if (err) {
10635 *param_optind = 1; 10638 shellparam.optind = 1;
10636 *optoff = -1; 10639 shellparam.optoff = -1;
10637 flush_stdout_stderr(); 10640 flush_stdout_stderr();
10638 raise_exception(EXERROR); 10641 raise_exception(EXERROR);
10639 } 10642 }
@@ -10667,8 +10670,7 @@ getoptscmd(int argc, char **argv)
10667 } 10670 }
10668 } 10671 }
10669 10672
10670 return getopts(argv[1], argv[2], optbase, &shellparam.optind, 10673 return getopts(argv[1], argv[2], optbase);
10671 &shellparam.optoff);
10672} 10674}
10673#endif /* ASH_GETOPTS */ 10675#endif /* ASH_GETOPTS */
10674 10676