summaryrefslogtreecommitdiff
path: root/dd.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2000-09-10 04:39:37 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2000-09-10 04:39:37 +0000
commit18310f1ce3fd2e2fd4ddce6da8ee6867f4196157 (patch)
tree8659d7094c5d62df6e1f40643855ff7f050f1e05 /dd.c
parent0ae8e5a645d9fba1623a370ec51b9008c6d1bc7c (diff)
downloadbusybox-w32-18310f1ce3fd2e2fd4ddce6da8ee6867f4196157.tar.gz
busybox-w32-18310f1ce3fd2e2fd4ddce6da8ee6867f4196157.tar.bz2
busybox-w32-18310f1ce3fd2e2fd4ddce6da8ee6867f4196157.zip
Using seek=? used to cause part of the original file to be zero'ed, i
think this was caused by opening the file in truncate mode.
Diffstat (limited to 'dd.c')
-rw-r--r--dd.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/dd.c b/dd.c
index 395f8c1e3..a7c8a2266 100644
--- a/dd.c
+++ b/dd.c
@@ -57,6 +57,7 @@ extern int dd_main(int argc, char **argv)
57 uintmax_t totalSize; 57 uintmax_t totalSize;
58 uintmax_t readSize; 58 uintmax_t readSize;
59 unsigned char buf[BUFSIZ]; 59 unsigned char buf[BUFSIZ];
60 off_t jumped;
60 61
61 argc--; 62 argc--;
62 argv++; 63 argv++;
@@ -117,7 +118,7 @@ extern int dd_main(int argc, char **argv)
117 if (outFile == NULL) 118 if (outFile == NULL)
118 outFd = fileno(stdout); 119 outFd = fileno(stdout);
119 else 120 else
120 outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666); 121 outFd = open(outFile, O_WRONLY | O_CREAT, 0666);
121 122
122 if (outFd < 0) { 123 if (outFd < 0) {
123 /* Note that we are not freeing buf or closing 124 /* Note that we are not freeing buf or closing
@@ -129,10 +130,9 @@ extern int dd_main(int argc, char **argv)
129 fatalError( outFile); 130 fatalError( outFile);
130 } 131 }
131 132
132 lseek(inFd, skipBlocks * blockSize, SEEK_SET); 133 lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET);
133 lseek(outFd, seekBlocks * blockSize, SEEK_SET); 134 jumped = lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET);
134 totalSize=count*blockSize; 135 totalSize=count*blockSize;
135 printf("totalsize is %d\n",(int) totalSize);
136 while ((readSize = totalSize - inTotal) > 0) { 136 while ((readSize = totalSize - inTotal) > 0) {
137 if (readSize > BUFSIZ) 137 if (readSize > BUFSIZ)
138 readSize=BUFSIZ; 138 readSize=BUFSIZ;
@@ -148,7 +148,6 @@ extern int dd_main(int argc, char **argv)
148#ifdef BB_FEATURE_CLEAN_UP 148#ifdef BB_FEATURE_CLEAN_UP
149 close(inFd); 149 close(inFd);
150 close(outFd); 150 close(outFd);
151 free(buf);
152#endif 151#endif
153 152
154 printf("%ld+%d records in\n", (long) (inTotal / blockSize), 153 printf("%ld+%d records in\n", (long) (inTotal / blockSize),