diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-11-29 22:33:02 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-11-29 22:33:02 +0000 |
commit | ddea368dbe50bd9bb3ca129037aa4ca1e28515ed (patch) | |
tree | 335749b651c96092554e01b9912d14680533bac2 /coreutils | |
parent | 618e8ed4c4bdb27875abdd725ddf342c5de19ac2 (diff) | |
download | busybox-w32-ddea368dbe50bd9bb3ca129037aa4ca1e28515ed.tar.gz busybox-w32-ddea368dbe50bd9bb3ca129037aa4ca1e28515ed.tar.bz2 busybox-w32-ddea368dbe50bd9bb3ca129037aa4ca1e28515ed.zip |
Apply rev #2 of dd fix from Gennady Feldman.
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/dd.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index 6868a913e..2b77ea6a5 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -49,14 +49,15 @@ extern int dd_main(int argc, char **argv) | |||
49 | int inCc = 0; | 49 | int inCc = 0; |
50 | int outCc; | 50 | int outCc; |
51 | int trunc=TRUE; | 51 | int trunc=TRUE; |
52 | long blockSize = 512; | 52 | int sync=FALSE; |
53 | long blockSize = 512,ibs; | ||
53 | uintmax_t skipBlocks = 0; | 54 | uintmax_t skipBlocks = 0; |
54 | uintmax_t seekBlocks = 0; | 55 | uintmax_t seekBlocks = 0; |
55 | uintmax_t count = (uintmax_t) - 1; | 56 | uintmax_t count = (uintmax_t) - 1; |
56 | uintmax_t inTotal = 0; | 57 | uintmax_t inTotal = 0; |
57 | uintmax_t outTotal = 0; | 58 | uintmax_t outTotal = 0; |
58 | uintmax_t totalSize; | 59 | uintmax_t totalSize; |
59 | uintmax_t readSize; | 60 | |
60 | unsigned char buf[BUFSIZ]; | 61 | unsigned char buf[BUFSIZ]; |
61 | char *keyword = NULL; | 62 | char *keyword = NULL; |
62 | 63 | ||
@@ -98,6 +99,8 @@ extern int dd_main(int argc, char **argv) | |||
98 | keyword = (strchr(*argv, '=') + 1); | 99 | keyword = (strchr(*argv, '=') + 1); |
99 | if (strcmp(keyword, "notrunc") == 0) | 100 | if (strcmp(keyword, "notrunc") == 0) |
100 | trunc=FALSE; | 101 | trunc=FALSE; |
102 | if (strcmp(keyword, "sync") == 0) | ||
103 | sync=TRUE; | ||
101 | } else { | 104 | } else { |
102 | goto usage; | 105 | goto usage; |
103 | } | 106 | } |
@@ -137,13 +140,24 @@ extern int dd_main(int argc, char **argv) | |||
137 | lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET); | 140 | lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET); |
138 | lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET); | 141 | lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET); |
139 | totalSize=count*blockSize; | 142 | totalSize=count*blockSize; |
140 | while ((readSize = totalSize - inTotal) > 0) { | 143 | |
141 | if (readSize > BUFSIZ) | 144 | ibs=blockSize; |
142 | readSize=BUFSIZ; | 145 | if (ibs > BUFSIZ) |
143 | inCc = fullRead(inFd, buf, readSize); | 146 | ibs=BUFSIZ; |
147 | |||
148 | while (totalSize > outTotal) { | ||
149 | inCc = fullRead(inFd, buf, ibs); | ||
144 | inTotal += inCc; | 150 | inTotal += inCc; |
145 | if ((outCc = fullWrite(outFd, buf, inCc)) < 1) | 151 | if ( (sync==TRUE) && (inCc>0) ) |
152 | while (inCc<ibs) | ||
153 | buf[inCc++]='\0'; | ||
154 | |||
155 | if ((outCc = fullWrite(outFd, buf, inCc)) < 1){ | ||
156 | if (outCc < 0 ){ | ||
157 | perror("Error during write"); | ||
158 | } | ||
146 | break; | 159 | break; |
160 | } | ||
147 | outTotal += outCc; | 161 | outTotal += outCc; |
148 | } | 162 | } |
149 | if (trunc == TRUE) { | 163 | if (trunc == TRUE) { |