summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMaxim Konovalov <maxim@FreeBSD.org>2006-10-21 16:02:08 +0000
committerMaxim Konovalov <maxim@FreeBSD.org>2006-10-21 16:02:08 +0000
commitc8cab6632bb368112a473d69c645e6b78c488d15 (patch)
tree2aa779d5b755278e7812e21556ae40967b9f6fe6 /bin
parent234143debbb9d0300f6100b59c42523ad77c7dea (diff)
downloadsrc-test2-c8cab6632bb368112a473d69c645e6b78c488d15.tar.gz
src-test2-c8cab6632bb368112a473d69c645e6b78c488d15.zip
Notes
Diffstat (limited to 'bin')
-rw-r--r--bin/cp/utils.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index d9e40b24542e..7eea8fa0b83f 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -54,17 +54,18 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include "extern.h"
-#define cp_pct(x,y) (int)(100.0 * (double)(x) / (double)(y))
+
+#define cp_pct(x, y) ((y == 0) ? 0 : (int)(100.0 * (x) / (y)))
int
copy_file(const FTSENT *entp, int dne)
{
static char buf[MAXBSIZE];
struct stat *fs;
- int ch, checkch, from_fd = 0, rcount, rval, to_fd = 0;
ssize_t wcount;
size_t wresid;
- size_t wtotal;
+ off_t wtotal;
+ int ch, checkch, from_fd = 0, rcount, rval, to_fd = 0;
char *bufp;
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
char *p;
@@ -149,16 +150,17 @@ copy_file(const FTSENT *entp, int dne)
for (bufp = p, wresid = fs->st_size; ;
bufp += wcount, wresid -= (size_t)wcount) {
wcount = write(to_fd, bufp, wresid);
+ if (wcount <= 0)
+ break;
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));
-
+ "%s -> %s %3d%%\n",
+ entp->fts_path, to.p_path,
+ cp_pct(wtotal, fs->st_size));
}
- if (wcount >= (ssize_t)wresid || wcount <= 0)
+ if (wcount >= (ssize_t)wresid)
break;
}
if (wcount != (ssize_t)wresid) {
@@ -179,16 +181,17 @@ copy_file(const FTSENT *entp, int dne)
for (bufp = buf, wresid = rcount; ;
bufp += wcount, wresid -= wcount) {
wcount = write(to_fd, bufp, wresid);
+ if (wcount <= 0)
+ break;
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));
-
+ "%s -> %s %3d%%\n",
+ entp->fts_path, to.p_path,
+ cp_pct(wtotal, fs->st_size));
}
- if (wcount >= (ssize_t)wresid || wcount <= 0)
+ if (wcount >= (ssize_t)wresid)
break;
}
if (wcount != (ssize_t)wresid) {