summaryrefslogtreecommitdiff
path: root/bin/cp
diff options
context:
space:
mode:
authorMatthew Dempsky <matthew@cvs.openbsd.org>2012-07-11 16:19:25 +0000
committerMatthew Dempsky <matthew@cvs.openbsd.org>2012-07-11 16:19:25 +0000
commit1196744ab82d167bf4b72f11565ccc8c64ae655d (patch)
tree9a496ba52e7722266532664d64abedc20ef263a2 /bin/cp
parentcb21ae2aca82a03c508dec61d1e9957d54e5c600 (diff)
When copying a file sparsely, truncate the resulting file based on the
current seek offset rather than what fstat() reported the original file's length was. This fixes things like "cp /dev/ksyms /tmp" so that we don't truncate the file to 0 bytes after copying all of the data. ok tedu, millert
Diffstat (limited to 'bin/cp')
-rw-r--r--bin/cp/utils.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index c45a6a4af32..dbe8cd14ee0 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: utils.c,v 1.32 2012/04/11 09:45:47 espie Exp $ */
+/* $OpenBSD: utils.c,v 1.33 2012/07/11 16:19:24 matthew Exp $ */
/* $NetBSD: utils.c,v 1.6 1997/02/26 14:40:51 cgd Exp $ */
/*-
@@ -158,7 +158,7 @@ copy_file(FTSENT *entp, int dne)
}
}
if (skipholes && rcount >= 0)
- rcount = ftruncate(to_fd, fs->st_size);
+ rcount = ftruncate(to_fd, lseek(to_fd, 0, SEEK_CUR));
if (rcount < 0) {
warn("%s", entp->fts_path);
rval = 1;