diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2000-09-11 00:32:13 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2000-09-11 00:32:13 +0000 |
commit | f0b073f55ac00a87c38e4e7aa66ee3543564779b (patch) | |
tree | 5a2024cd2cf880f4e4b861acab636e11bc14d5b7 /coreutils | |
parent | de34e4375565cbe1b60c2d99afddfb6c7c45b3ad (diff) | |
download | busybox-w32-f0b073f55ac00a87c38e4e7aa66ee3543564779b.tar.gz busybox-w32-f0b073f55ac00a87c38e4e7aa66ee3543564779b.tar.bz2 busybox-w32-f0b073f55ac00a87c38e4e7aa66ee3543564779b.zip |
dd now truncates files at the end its write, this can be turned of by
specifying conv=notrunc in the command line
This conforms to GNU dd behaviour
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/dd.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index 84f3211fb..5ab0a90af 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -48,6 +48,7 @@ extern int dd_main(int argc, char **argv) | |||
48 | int outFd; | 48 | int outFd; |
49 | int inCc = 0; | 49 | int inCc = 0; |
50 | int outCc; | 50 | int outCc; |
51 | int trunc=TRUE; | ||
51 | long blockSize = 512; | 52 | long blockSize = 512; |
52 | uintmax_t skipBlocks = 0; | 53 | uintmax_t skipBlocks = 0; |
53 | uintmax_t seekBlocks = 0; | 54 | uintmax_t seekBlocks = 0; |
@@ -57,6 +58,7 @@ extern int dd_main(int argc, char **argv) | |||
57 | uintmax_t totalSize; | 58 | uintmax_t totalSize; |
58 | uintmax_t readSize; | 59 | uintmax_t readSize; |
59 | unsigned char buf[BUFSIZ]; | 60 | unsigned char buf[BUFSIZ]; |
61 | char *keyword = NULL; | ||
60 | 62 | ||
61 | argc--; | 63 | argc--; |
62 | argv++; | 64 | argv++; |
@@ -69,7 +71,7 @@ extern int dd_main(int argc, char **argv) | |||
69 | outFile = ((strchr(*argv, '=')) + 1); | 71 | outFile = ((strchr(*argv, '=')) + 1); |
70 | else if (strncmp("count", *argv, 5) == 0) { | 72 | else if (strncmp("count", *argv, 5) == 0) { |
71 | count = getNum((strchr(*argv, '=')) + 1); | 73 | count = getNum((strchr(*argv, '=')) + 1); |
72 | if (count <= 0) { | 74 | if (count < 0) { |
73 | errorMsg("Bad count value %s\n", *argv); | 75 | errorMsg("Bad count value %s\n", *argv); |
74 | goto usage; | 76 | goto usage; |
75 | } | 77 | } |
@@ -92,7 +94,10 @@ extern int dd_main(int argc, char **argv) | |||
92 | errorMsg("Bad seek value %s\n", *argv); | 94 | errorMsg("Bad seek value %s\n", *argv); |
93 | goto usage; | 95 | goto usage; |
94 | } | 96 | } |
95 | 97 | } else if (strncmp(*argv, "conv", 4) == 0) { | |
98 | keyword = (strchr(*argv, '=') + 1); | ||
99 | if (strcmp(keyword, "notrunc") == 0) | ||
100 | trunc=FALSE; | ||
96 | } else { | 101 | } else { |
97 | goto usage; | 102 | goto usage; |
98 | } | 103 | } |
@@ -141,7 +146,9 @@ extern int dd_main(int argc, char **argv) | |||
141 | break; | 146 | break; |
142 | outTotal += outCc; | 147 | outTotal += outCc; |
143 | } | 148 | } |
144 | 149 | if (trunc == TRUE) { | |
150 | ftruncate(outFd, lseek(outFd, 0, SEEK_CUR)); | ||
151 | } | ||
145 | /* Note that we are not freeing memory or closing | 152 | /* Note that we are not freeing memory or closing |
146 | * files here, to save a few bytes. */ | 153 | * files here, to save a few bytes. */ |
147 | #ifdef BB_FEATURE_CLEAN_UP | 154 | #ifdef BB_FEATURE_CLEAN_UP |