summaryrefslogtreecommitdiffstats
path: root/bin/cp/utils.c
diff options
context:
space:
mode:
authormdodd <mdodd@FreeBSD.org>2003-04-07 11:00:56 +0000
committermdodd <mdodd@FreeBSD.org>2003-04-07 11:00:56 +0000
commit7e2b8444e09a4666ef4570568088b984d18c2ad0 (patch)
treea47801209e48fd3a1334b3a004a8871921681469 /bin/cp/utils.c
parentf8221d23db2ef003ca10f5a62ec719a74430963d (diff)
downloadFreeBSD-src-7e2b8444e09a4666ef4570568088b984d18c2ad0.zip
FreeBSD-src-7e2b8444e09a4666ef4570568088b984d18c2ad0.tar.gz
Add a SIGINFO handler.
Diffstat (limited to 'bin/cp/utils.c')
-rw-r--r--bin/cp/utils.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index 7930195..aa1559e 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include "extern.h"
+#define cp_pct(x,y) (int)(100.0 * (double)(x) / (double)(y))
int
copy_file(const FTSENT *entp, int dne)
@@ -65,6 +66,7 @@ copy_file(const FTSENT *entp, int dne)
int ch, checkch, from_fd, rcount, rval, to_fd;
ssize_t wcount;
size_t wresid;
+ size_t wtotal;
char *bufp;
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
char *p;
@@ -137,9 +139,19 @@ copy_file(const FTSENT *entp, int dne)
warn("%s", entp->fts_path);
rval = 1;
} else {
+ wtotal = 0;
for (bufp = p, wresid = fs->st_size; ;
bufp += wcount, wresid -= (size_t)wcount) {
wcount = write(to_fd, bufp, wresid);
+ wtotal += wcount;
+ if (info) {
+ info = 0;
+ (void)fprintf(stderr,
+ "%s -> %s %3d%%\n",
+ entp->fts_path, to.p_path,
+ cp_pct(wtotal, fs->st_size));
+
+ }
if (wcount >= (ssize_t)wresid || wcount <= 0)
break;
}
@@ -156,10 +168,20 @@ copy_file(const FTSENT *entp, int dne)
} else
#endif
{
+ wtotal = 0;
while ((rcount = read(from_fd, buf, MAXBSIZE)) > 0) {
for (bufp = buf, wresid = rcount; ;
bufp += wcount, wresid -= wcount) {
wcount = write(to_fd, bufp, wresid);
+ wtotal += wcount;
+ if (info) {
+ info = 0;
+ (void)fprintf(stderr,
+ "%s -> %s %3d%%\n",
+ entp->fts_path, to.p_path,
+ cp_pct(wtotal, fs->st_size));
+
+ }
if (wcount >= (ssize_t)wresid || wcount <= 0)
break;
}
OpenPOWER on IntegriCloud