summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-12-22 00:21:07 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-12-22 00:21:07 +0000
commit714701c890b5f03253c5ecdb7367c4258ce78715 (patch)
tree7ddaf73cf2deda0f357b21802dab4d42798dd778 /libbb
parent0a8a7741795880201bcf78231d1eab0e2538bb0b (diff)
downloadbusybox-w32-714701c890b5f03253c5ecdb7367c4258ce78715.tar.gz
busybox-w32-714701c890b5f03253c5ecdb7367c4258ce78715.tar.bz2
busybox-w32-714701c890b5f03253c5ecdb7367c4258ce78715.zip
tar et al: die if bb_copyfd_size copies less than asked for.
(we have bb_copyfd_exact_size now for that kind of usage)
Diffstat (limited to 'libbb')
-rw-r--r--libbb/copyfd.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/libbb/copyfd.c b/libbb/copyfd.c
index c6b886647..17bf4fbc2 100644
--- a/libbb/copyfd.c
+++ b/libbb/copyfd.c
@@ -39,7 +39,7 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
39 39
40 rd = safe_read(src_fd, buffer, size > BUFSIZ ? BUFSIZ : size); 40 rd = safe_read(src_fd, buffer, size > BUFSIZ ? BUFSIZ : size);
41 41
42 if (!rd) { /* eof - all done. */ 42 if (!rd) { /* eof - all done */
43 status = 0; 43 status = 0;
44 break; 44 break;
45 } 45 }
@@ -56,22 +56,31 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
56 } 56 }
57 } 57 }
58 total += rd; 58 total += rd;
59 if (status < 0) { 59 if (status < 0) { /* if we aren't copying till EOF... */
60 size -= rd; 60 size -= rd;
61 if (!size) { 61 if (!size) {
62 status = 0; 62 /* 'size' bytes copied - all done */
63 status = 0;
63 break; 64 break;
64 } 65 }
65 } 66 }
66 } 67 }
67 68 out:
68out:
69 RELEASE_CONFIG_BUFFER(buffer); 69 RELEASE_CONFIG_BUFFER(buffer);
70
71 return status ? -1 : total; 70 return status ? -1 : total;
72} 71}
73 72
74 73
74#if 0
75void complain_copyfd_and_die(off_t sz)
76{
77 if (sz != -1)
78 bb_error_msg_and_die("short read");
79 /* if sz == -1, bb_copyfd_XX already complained */
80 exit(xfunc_error_retval);
81}
82#endif
83
75off_t bb_copyfd_size(int fd1, int fd2, off_t size) 84off_t bb_copyfd_size(int fd1, int fd2, off_t size)
76{ 85{
77 if (size) { 86 if (size) {
@@ -80,6 +89,17 @@ off_t bb_copyfd_size(int fd1, int fd2, off_t size)
80 return 0; 89 return 0;
81} 90}
82 91
92void bb_copyfd_exact_size(int fd1, int fd2, off_t size)
93{
94 off_t sz = bb_copyfd_size(fd1, fd2, size);
95 if (sz == size)
96 return;
97 if (sz != -1)
98 bb_error_msg_and_die("short read");
99 /* if sz == -1, bb_copyfd_XX already complained */
100 exit(xfunc_error_retval);
101}
102
83off_t bb_copyfd_eof(int fd1, int fd2) 103off_t bb_copyfd_eof(int fd1, int fd2)
84{ 104{
85 return bb_full_fd_action(fd1, fd2, 0); 105 return bb_full_fd_action(fd1, fd2, 0);