o Avoid division by zero.
o Place error checking code near to the syscall. Submitted by: bde
This commit is contained in:
parent
dfe25dc456
commit
eb82e1a1f8
@ -54,7 +54,8 @@ __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)
|
||||
@ -149,6 +150,8 @@ 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;
|
||||
@ -158,7 +161,7 @@ copy_file(const FTSENT *entp, int dne)
|
||||
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,6 +182,8 @@ 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;
|
||||
@ -188,7 +193,7 @@ copy_file(const FTSENT *entp, int dne)
|
||||
cp_pct(wtotal, fs->st_size));
|
||||
|
||||
}
|
||||
if (wcount >= (ssize_t)wresid || wcount <= 0)
|
||||
if (wcount >= (ssize_t)wresid)
|
||||
break;
|
||||
}
|
||||
if (wcount != (ssize_t)wresid) {
|
||||
|
Loading…
Reference in New Issue
Block a user