summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2001-01-17 00:21:05 +0000
committerMatt Kraai <kraai@debian.org>2001-01-17 00:21:05 +0000
commitc9acf8c766a9a2cc00449db5dea506d7663ad26b (patch)
treeaf94dcea7206980094332a1131dd244983d9759b /coreutils
parentfd4c58d7c5a8cd8dd72ea5fc4eb16828be998792 (diff)
downloadbusybox-w32-c9acf8c766a9a2cc00449db5dea506d7663ad26b.tar.gz
busybox-w32-c9acf8c766a9a2cc00449db5dea506d7663ad26b.tar.bz2
busybox-w32-c9acf8c766a9a2cc00449db5dea506d7663ad26b.zip
Complicate truncate behavior.
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/dd.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index a0d2330ea..32eeb661c 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -41,7 +41,7 @@ static struct suffix_mult dd_suffixes[] = {
41 41
42int dd_main(int argc, char **argv) 42int dd_main(int argc, char **argv)
43{ 43{
44 int i, ifd, ofd, sync = FALSE, trunc = TRUE; 44 int i, ifd, ofd, oflag, sync = FALSE, trunc = TRUE;
45 size_t in_full = 0, in_part = 0, out_full = 0, out_part = 0; 45 size_t in_full = 0, in_part = 0, out_full = 0, out_part = 0;
46 size_t bs = 512, count = -1; 46 size_t bs = 512, count = -1;
47 ssize_t n; 47 ssize_t n;
@@ -94,8 +94,19 @@ int dd_main(int argc, char **argv)
94 } 94 }
95 95
96 if (outfile != NULL) { 96 if (outfile != NULL) {
97 if ((ofd = open(outfile, O_WRONLY | O_CREAT, 0666)) < 0) 97 oflag = O_WRONLY | O_CREAT;
98
99 if (!seek && trunc)
100 oflag |= O_TRUNC;
101
102 if ((ofd = open(outfile, oflag, 0666)) < 0)
98 perror_msg_and_die("%s", outfile); 103 perror_msg_and_die("%s", outfile);
104
105 if (seek && trunc) {
106 if (ftruncate(ofd, seek * bs) < 0)
107 perror_msg_and_die("%s", outfile);
108 }
109
99 statusfp = stdout; 110 statusfp = stdout;
100 } else { 111 } else {
101 ofd = STDOUT_FILENO; 112 ofd = STDOUT_FILENO;
@@ -113,11 +124,6 @@ int dd_main(int argc, char **argv)
113 perror_msg_and_die("%s", outfile); 124 perror_msg_and_die("%s", outfile);
114 } 125 }
115 126
116 if (trunc) {
117 if (ftruncate(ofd, seek * bs) < 0)
118 perror_msg_and_die("%s", outfile);
119 }
120
121 while (in_full + in_part != count) { 127 while (in_full + in_part != count) {
122 n = safe_read(ifd, buf, bs); 128 n = safe_read(ifd, buf, bs);
123 if (n < 0) 129 if (n < 0)