summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2000-09-10 01:54:27 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2000-09-10 01:54:27 +0000
commit0ae8e5a645d9fba1623a370ec51b9008c6d1bc7c (patch)
treeac7ace19652f72fd2bae22c735f5c23b93a1b7a9 /coreutils
parentbd7c67136ac961f4dd8b06514ca00de900cd1f8c (diff)
downloadbusybox-w32-0ae8e5a645d9fba1623a370ec51b9008c6d1bc7c.tar.gz
busybox-w32-0ae8e5a645d9fba1623a370ec51b9008c6d1bc7c.tar.bz2
busybox-w32-0ae8e5a645d9fba1623a370ec51b9008c6d1bc7c.zip
My previous attempt to make dd use fullRead, fullWrite was very broken,
this should actually work.
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/dd.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 787e5da95..395f8c1e3 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -52,9 +52,11 @@ extern int dd_main(int argc, char **argv)
52 uintmax_t skipBlocks = 0; 52 uintmax_t skipBlocks = 0;
53 uintmax_t seekBlocks = 0; 53 uintmax_t seekBlocks = 0;
54 uintmax_t count = (uintmax_t) - 1; 54 uintmax_t count = (uintmax_t) - 1;
55 uintmax_t intotal; 55 uintmax_t inTotal = 0;
56 uintmax_t outTotal; 56 uintmax_t outTotal = 0;
57 unsigned char *buf; 57 uintmax_t totalSize;
58 uintmax_t readSize;
59 unsigned char buf[BUFSIZ];
58 60
59 argc--; 61 argc--;
60 argv++; 62 argv++;
@@ -98,11 +100,6 @@ extern int dd_main(int argc, char **argv)
98 argv++; 100 argv++;
99 } 101 }
100 102
101 buf = xmalloc(blockSize);
102
103 intotal = 0;
104 outTotal = 0;
105
106 if (inFile == NULL) 103 if (inFile == NULL)
107 inFd = fileno(stdin); 104 inFd = fileno(stdin);
108 else 105 else
@@ -134,9 +131,13 @@ extern int dd_main(int argc, char **argv)
134 131
135 lseek(inFd, skipBlocks * blockSize, SEEK_SET); 132 lseek(inFd, skipBlocks * blockSize, SEEK_SET);
136 lseek(outFd, seekBlocks * blockSize, SEEK_SET); 133 lseek(outFd, seekBlocks * blockSize, SEEK_SET);
137 134 totalSize=count*blockSize;
138 while ((inCc = read(inFd, buf, sizeof(buf))) > 0) { 135 printf("totalsize is %d\n",(int) totalSize);
139 intotal +=inCc; 136 while ((readSize = totalSize - inTotal) > 0) {
137 if (readSize > BUFSIZ)
138 readSize=BUFSIZ;
139 inCc = read(inFd, buf, readSize);
140 inTotal += inCc;
140 if ((outCc = fullWrite(outFd, buf, inCc)) < 0) 141 if ((outCc = fullWrite(outFd, buf, inCc)) < 0)
141 break; 142 break;
142 outTotal += outCc; 143 outTotal += outCc;
@@ -150,8 +151,8 @@ extern int dd_main(int argc, char **argv)
150 free(buf); 151 free(buf);
151#endif 152#endif
152 153
153 printf("%ld+%d records in\n", (long) (intotal / blockSize), 154 printf("%ld+%d records in\n", (long) (inTotal / blockSize),
154 (intotal % blockSize) != 0); 155 (inTotal % blockSize) != 0);
155 printf("%ld+%d records out\n", (long) (outTotal / blockSize), 156 printf("%ld+%d records out\n", (long) (outTotal / blockSize),
156 (outTotal % blockSize) != 0); 157 (outTotal % blockSize) != 0);
157 exit(TRUE); 158 exit(TRUE);