Audit cp(1)
1) Refactor the manpage, which has been a bloody mess, documenting fantasy-flags (-d for example) and add a STANDARDS section 2) fix usage() 3) sort ARG-block 4) Check return-value of stat() separately, so a lack of permissions doesn't tell the user "the directory doesn't exist", which could be a bit confusing. 5) Add empty line before return.
This commit is contained in:
17
cp.c
17
cp.c
@@ -7,7 +7,7 @@
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
eprintf("usage: %s [-afpv] [-R [-H | -L | -P]] source... dest\n", argv0);
|
||||
eprintf("usage: %s [-afpv] [-R [-H | -L | -P]] source ... dest\n", argv0);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -26,13 +26,13 @@ main(int argc, char *argv[])
|
||||
case 'p':
|
||||
cp_pflag = 1;
|
||||
break;
|
||||
case 'v':
|
||||
cp_vflag = 1;
|
||||
break;
|
||||
case 'r':
|
||||
case 'R':
|
||||
cp_rflag = 1;
|
||||
break;
|
||||
case 'v':
|
||||
cp_vflag = 1;
|
||||
break;
|
||||
case 'H':
|
||||
case 'L':
|
||||
case 'P':
|
||||
@@ -45,8 +45,13 @@ main(int argc, char *argv[])
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
||||
if (argc > 2 && !(stat(argv[argc-1], &st) == 0 && S_ISDIR(st.st_mode)))
|
||||
eprintf("%s: not a directory\n", argv[argc-1]);
|
||||
if (argc > 2) {
|
||||
if (stat(argv[argc - 1], &st) < 0)
|
||||
eprintf("stat %s:", argv[argc - 1]);
|
||||
if (!S_ISDIR(st.st_mode))
|
||||
eprintf("%s: not a directory\n", argv[argc - 1]);
|
||||
}
|
||||
enmasse(argc, argv, cp, cp_HLPflag);
|
||||
|
||||
return cp_status;
|
||||
}
|
||||
|
Reference in New Issue
Block a user