cp: add -v, fix manpage info

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
This commit is contained in:
Hiltjo Posthuma 2014-07-10 20:30:30 +00:00 committed by sin
parent ac402965d5
commit f67320ce93
5 changed files with 15 additions and 5 deletions

8
cp.1
View File

@ -8,7 +8,7 @@ cp \- copy files and directories
.RI [ name ]
.P
.B cp
.RB [ \-adpRr ]
.RB [ \-adpRrv ]
.RI [ file ...]
.RI [ directory ]
.SH DESCRIPTION
@ -25,7 +25,7 @@ Implies \-d, \-p, \-r.
don't dereference links. preserve links.
.TP
.B \-p
preserve mode, timestamp, links and permissions.
preserve mode, timestamp and permissions.
.TP
.B \-f
if an existing destination file cannot be opened, remove it and try again.
@ -36,3 +36,7 @@ equivalent to -r.
.B \-r
copies directories recursively. If this flag is not specified, directories are
not copied.
.TP
.B \-v
print names of source and destination per file to stdout. In the format:
"source \-> destination".

5
cp.c
View File

@ -8,7 +8,7 @@
static void
usage(void)
{
eprintf("usage: %s [-adfpRr] source... dest\n", argv0);
eprintf("usage: %s [-adfpRrv] source... dest\n", argv0);
}
int
@ -36,6 +36,9 @@ main(int argc, char *argv[])
case 'r':
cp_rflag = true;
break;
case 'v':
cp_vflag = true;
break;
default:
usage();
} ARGEND;

1
fs.h
View File

@ -6,6 +6,7 @@ extern bool cp_dflag;
extern bool cp_fflag;
extern bool cp_pflag;
extern bool cp_rflag;
extern bool cp_vflag;
extern bool rm_fflag;
extern bool rm_rflag;

View File

@ -22,4 +22,3 @@ apathmax(char **p, long *size)
if(!(*p = malloc(*size)))
eprintf("malloc:");
}

View File

@ -20,6 +20,7 @@ bool cp_dflag = false;
bool cp_fflag = false;
bool cp_pflag = false;
bool cp_rflag = false;
bool cp_vflag = false;
int
cp(const char *s1, const char *s2)
@ -39,6 +40,9 @@ cp(const char *s1, const char *s2)
else
r = stat(s1, &st);
if(cp_vflag)
printf("'%s' -> '%s'\n", s1, s2);
if(r == 0) {
if(cp_dflag == true && S_ISLNK(st.st_mode)) {
if(cp_fflag == true)
@ -86,7 +90,6 @@ cp(const char *s1, const char *s2)
free(ns1);
free(ns2);
goto preserve;
return 0;
}
}
if(!(f1 = fopen(s1, "r")))