Do not interpret -[rwxs] as options in chmod(1)

To chmod recursively use `-R' as opposed to `-r' so we can
distinguish it from the mode `-r'.
This commit is contained in:
sin 2013-10-10 14:50:52 +01:00
parent 6492c59072
commit d8718d4159

38
chmod.c
View File

@ -16,26 +16,44 @@ static mode_t mode = 0;
static void static void
usage(void) usage(void)
{ {
eprintf("usage: %s [-r] mode [file...]\n", argv0); eprintf("usage: %s [-R] mode [file...]\n", argv0);
} }
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int c;
argv0 = argv[0];
ARGBEGIN { while (--argc > 0 && (*++argv)[0] == '-') {
case 'r': while ((c = *++argv[0])) {
rflag = true; switch (c) {
break; case 'R':
default: rflag = true;
usage(); break;
} ARGEND; case 'r': case 'w': case 'x': case 's':
/*
* -[rwxs] are valid modes so do not interpret
* them as options - in any case we are done if
* we hit this case
*/
--argv[0];
goto done;
default:
usage();
}
}
}
done:
parsemode(argv[0]);
argv++;
argc--;
if(argc < 1) if(argc < 1)
usage(); usage();
parsemode(argv[0]); for (; argc > 0; argc--, argv++)
for(++argv; argc > 0; argc--)
chmodr(argv[0]); chmodr(argv[0]);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }