aboutsummaryrefslogtreecommitdiff
path: root/dd.c
diff options
context:
space:
mode:
Diffstat (limited to 'dd.c')
-rw-r--r--dd.c41
1 files changed, 6 insertions, 35 deletions
diff --git a/dd.c b/dd.c
index 6df2588ca..787e5da95 100644
--- a/dd.c
+++ b/dd.c
@@ -44,7 +44,6 @@ extern int dd_main(int argc, char **argv)
44{ 44{
45 char *inFile = NULL; 45 char *inFile = NULL;
46 char *outFile = NULL; 46 char *outFile = NULL;
47 char *cp;
48 int inFd; 47 int inFd;
49 int outFd; 48 int outFd;
50 int inCc = 0; 49 int inCc = 0;
@@ -135,42 +134,14 @@ extern int dd_main(int argc, char **argv)
135 134
136 lseek(inFd, skipBlocks * blockSize, SEEK_SET); 135 lseek(inFd, skipBlocks * blockSize, SEEK_SET);
137 lseek(outFd, seekBlocks * blockSize, SEEK_SET); 136 lseek(outFd, seekBlocks * blockSize, SEEK_SET);
138 //
139 //TODO: Convert to using fullRead & fullWrite
140 // from utility.c
141 // -Erik
142 while (outTotal < count * blockSize) {
143 inCc = read(inFd, buf, blockSize);
144 if (inCc < 0) {
145 perror(inFile);
146 goto cleanup;
147 } else if (inCc == 0) {
148 goto cleanup;
149 }
150 intotal += inCc;
151 cp = buf;
152
153 while (intotal > outTotal) {
154 if (outTotal + inCc > count * blockSize)
155 inCc = count * blockSize - outTotal;
156 outCc = write(outFd, cp, inCc);
157 if (outCc < 0) {
158 perror(outFile);
159 goto cleanup;
160 } else if (outCc == 0) {
161 goto cleanup;
162 }
163
164 inCc -= outCc;
165 cp += outCc;
166 outTotal += outCc;
167 }
168 }
169 137
170 if (inCc < 0) 138 while ((inCc = read(inFd, buf, sizeof(buf))) > 0) {
171 perror(inFile); 139 intotal +=inCc;
140 if ((outCc = fullWrite(outFd, buf, inCc)) < 0)
141 break;
142 outTotal += outCc;
143 }
172 144
173 cleanup:
174 /* Note that we are not freeing memory or closing 145 /* Note that we are not freeing memory or closing
175 * files here, to save a few bytes. */ 146 * files here, to save a few bytes. */
176#ifdef BB_FEATURE_CLEAN_UP 147#ifdef BB_FEATURE_CLEAN_UP