Fix an option parsing bug where things like

chmod -r /tmp/file
wholdn't work (since it thought -r was an option).  Doh!
 -Erik
This commit is contained in:
Eric Andersen 2000-08-22 01:00:56 +00:00
parent 2368a387ed
commit ce82c8ab77

View File

@ -76,6 +76,7 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
int chmod_chown_chgrp_main(int argc, char **argv) int chmod_chown_chgrp_main(int argc, char **argv)
{ {
int stopIt = FALSE;
int recursiveFlag = FALSE; int recursiveFlag = FALSE;
char *groupName=NULL; char *groupName=NULL;
char *p=NULL; char *p=NULL;
@ -94,25 +95,27 @@ int chmod_chown_chgrp_main(int argc, char **argv)
/* Parse options */ /* Parse options */
while (--argc >= 0 && *argv && (**argv == '-')) { while (--argc >= 0 && *argv && (**argv == '-')) {
while (*++(*argv)) { while (stopIt==FALSE && *++(*argv)) {
switch (**argv) { switch (**argv) {
case 'R': case 'R':
recursiveFlag = TRUE; recursiveFlag = TRUE;
break; break;
default: default:
errorMsg(invalid_option, **argv); theMode=*argv-1;
usage(appUsage); stopIt = TRUE;
} }
} }
if (stopIt==TRUE)
break;
argv++; argv++;
} }
if (argc == 0 || *argv == NULL) { if (argc == 0 || *argv == NULL) {
errorMsg(too_few_args); errorMsg(too_few_args);
usage(appUsage);
} }
if (whichApp == CHMOD_APP) { if (whichApp == CHMOD_APP) {
if (theMode==NULL)
theMode = *argv; theMode = *argv;
} else { } else {
@ -152,7 +155,7 @@ int chmod_chown_chgrp_main(int argc, char **argv)
} }
/* Ok, ready to do the deed now */ /* Ok, ready to do the deed now */
if (argc <= 1) { if (argc < 1) {
fatalError(too_few_args); fatalError(too_few_args);
} }
while (argc-- > 1) { while (argc-- > 1) {