summaryrefslogtreecommitdiffstats
path: root/bin/cp
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1998-01-16 07:37:05 +0000
committerbde <bde@FreeBSD.org>1998-01-16 07:37:05 +0000
commit356127f254dab2cbb005babb7b76c2791349873f (patch)
tree72f114a86699137d7b25c61d4bf51db601cda68e /bin/cp
parentaeb756ae62a96eaa0e7a67308cc4084b251a5597 (diff)
downloadFreeBSD-src-356127f254dab2cbb005babb7b76c2791349873f.zip
FreeBSD-src-356127f254dab2cbb005babb7b76c2791349873f.tar.gz
Fixed handling of short writes. Previously, we stopped copying and
printed a bogus warning with a stale errno if write() returns a short count. Now we continue copying. We still print a bogus warning if write() returns an "impossible" short count of 0.
Diffstat (limited to 'bin/cp')
-rw-r--r--bin/cp/utils.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index ecd9790..85de4a4 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: utils.c,v 1.13 1997/02/22 14:01:34 peter Exp $
+ * $Id: utils.c,v 1.14 1997/10/03 18:11:14 wosch Exp $
*/
#ifndef lint
@@ -60,7 +60,8 @@ copy_file(entp, dne)
{
static char buf[MAXBSIZE];
struct stat to_stat, *fs;
- int ch, checkch, from_fd, rcount, rval, to_fd, wcount;
+ int ch, checkch, from_fd, rcount, rval, to_fd, wcount, wresid;
+ char *bufp;
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
char *p;
#endif
@@ -128,7 +129,13 @@ copy_file(entp, dne)
warn("%s", entp->fts_path);
rval = 1;
} else {
- if (write(to_fd, p, fs->st_size) != fs->st_size) {
+ for (bufp = p, wresid = fs->st_size; ;
+ bufp += wcount, wresid -= wcount)
+ wcount = write(to_fd, bufp, wresid);
+ if (wcount >= wresid || wcount <= 0)
+ break;
+ }
+ if (wcount != wresid) {
warn("%s", to.p_path);
rval = 1;
}
@@ -142,8 +149,13 @@ copy_file(entp, dne)
#endif
{
while ((rcount = read(from_fd, buf, MAXBSIZE)) > 0) {
- wcount = write(to_fd, buf, rcount);
- if (rcount != wcount || wcount == -1) {
+ for (bufp = buf, wresid = rcount; ;
+ bufp += wcount, wresid -= wcount) {
+ wcount = write(to_fd, bufp, wresid);
+ if (wcount >= wresid || wcount <= 0)
+ break;
+ }
+ if (wcount != wresid) {
warn("%s", to.p_path);
rval = 1;
break;
OpenPOWER on IntegriCloud