Checking validity of mode as a number (not implemented as a string though)
This commit is contained in:
parent
b15cf7275d
commit
291e52953a
10
src/chmod.c
10
src/chmod.c
|
@ -102,7 +102,8 @@ static int _chmod_do_recursive_do(int opts, mode_t mode, char * file)
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s", "Usage: chmod [-R] mode file\n");
|
fprintf(stderr, "%s", "Usage: chmod [-R] mode file\n\
|
||||||
|
-R recursively change file mode bits\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +114,7 @@ int main(int argc, char * argv[])
|
||||||
int opts = 0;
|
int opts = 0;
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
int o;
|
int o;
|
||||||
|
char * p;
|
||||||
|
|
||||||
while((o = getopt(argc, argv, "R")) != -1)
|
while((o = getopt(argc, argv, "R")) != -1)
|
||||||
{
|
{
|
||||||
|
@ -127,7 +129,9 @@ int main(int argc, char * argv[])
|
||||||
}
|
}
|
||||||
if(argc - optind < 2)
|
if(argc - optind < 2)
|
||||||
return _usage();
|
return _usage();
|
||||||
/* FIXME */
|
/* FIXME mode may be an expression */
|
||||||
mode = strtol(argv[optind], NULL, 8);
|
mode = strtol(argv[optind], &p, 8);
|
||||||
|
if(argv[optind][0] == '\0' || *p != '\0')
|
||||||
|
return _usage();
|
||||||
return _chmod(opts, mode, argc - optind - 1, &argv[optind+1]);
|
return _chmod(opts, mode, argc - optind - 1, &argv[optind+1]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user