From f67320ce937c21b85b4e0bfb1ee4c3e21e9801fb Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Thu, 10 Jul 2014 20:30:30 +0000 Subject: [PATCH] cp: add -v, fix manpage info Signed-off-by: Hiltjo Posthuma --- cp.1 | 8 ++++++-- cp.c | 5 ++++- fs.h | 1 + util/apathmax.c | 1 - util/cp.c | 5 ++++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cp.1 b/cp.1 index 85eb47b..f0f5b65 100644 --- a/cp.1 +++ b/cp.1 @@ -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". diff --git a/cp.c b/cp.c index 9e3ded3..62f4593 100644 --- a/cp.c +++ b/cp.c @@ -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; diff --git a/fs.h b/fs.h index 3d9c795..cb66856 100644 --- a/fs.h +++ b/fs.h @@ -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; diff --git a/util/apathmax.c b/util/apathmax.c index 5dc831f..109f0ac 100644 --- a/util/apathmax.c +++ b/util/apathmax.c @@ -22,4 +22,3 @@ apathmax(char **p, long *size) if(!(*p = malloc(*size))) eprintf("malloc:"); } - diff --git a/util/cp.c b/util/cp.c index ebad41a..c50a81c 100644 --- a/util/cp.c +++ b/util/cp.c @@ -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")))