diff options
author | Eric Andersen <andersen@codepoet.org> | 2002-04-27 01:31:43 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2002-04-27 01:31:43 +0000 |
commit | ef38b392627b31abf6b99273311d2a155023e73a (patch) | |
tree | 8a9352d2558a97ccbc65490a28d66ea39bc4347e | |
parent | aba75460e4ca8415e9dd3b07ed3511126724dbd9 (diff) | |
download | busybox-w32-ef38b392627b31abf6b99273311d2a155023e73a.tar.gz busybox-w32-ef38b392627b31abf6b99273311d2a155023e73a.tar.bz2 busybox-w32-ef38b392627b31abf6b99273311d2a155023e73a.zip |
Support noerror option
-rw-r--r-- | coreutils/dd.c | 19 | ||||
-rw-r--r-- | include/usage.h | 3 |
2 files changed, 18 insertions, 4 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index 09e6cccc7..fb78d5355 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -46,7 +46,7 @@ static const struct suffix_mult dd_suffixes[] = { | |||
46 | 46 | ||
47 | int dd_main(int argc, char **argv) | 47 | int dd_main(int argc, char **argv) |
48 | { | 48 | { |
49 | int i, ifd, ofd, oflag, sync_flag = FALSE, trunc = TRUE; | 49 | int i, ifd, ofd, oflag, sync_flag = FALSE, trunc = TRUE, noerror = FALSE; |
50 | size_t in_full = 0, in_part = 0, out_full = 0, out_part = 0; | 50 | size_t in_full = 0, in_part = 0, out_full = 0, out_part = 0; |
51 | size_t bs = 512, count = -1; | 51 | size_t bs = 512, count = -1; |
52 | ssize_t n; | 52 | ssize_t n; |
@@ -75,6 +75,9 @@ int dd_main(int argc, char **argv) | |||
75 | } else if (strncmp("sync", buf, 4) == 0) { | 75 | } else if (strncmp("sync", buf, 4) == 0) { |
76 | sync_flag = TRUE; | 76 | sync_flag = TRUE; |
77 | buf += 4; | 77 | buf += 4; |
78 | } else if (strncmp("noerror", buf, 7) == 0) { | ||
79 | noerror = TRUE; | ||
80 | buf += 7; | ||
78 | } else { | 81 | } else { |
79 | error_msg_and_die("invalid conversion `%s'", argv[i]+5); | 82 | error_msg_and_die("invalid conversion `%s'", argv[i]+5); |
80 | } | 83 | } |
@@ -131,9 +134,19 @@ int dd_main(int argc, char **argv) | |||
131 | } | 134 | } |
132 | 135 | ||
133 | while (in_full + in_part != count) { | 136 | while (in_full + in_part != count) { |
137 | if (noerror) { | ||
138 | /* Pre-zero the buffer when doing the noerror thing */ | ||
139 | memset(buf, '\0', bs); | ||
140 | } | ||
134 | n = safe_read(ifd, buf, bs); | 141 | n = safe_read(ifd, buf, bs); |
135 | if (n < 0) | 142 | if (n < 0) { |
136 | perror_msg_and_die("%s", infile); | 143 | if (noerror) { |
144 | n = bs; | ||
145 | perror_msg("%s", infile); | ||
146 | } else { | ||
147 | perror_msg_and_die("%s", infile); | ||
148 | } | ||
149 | } | ||
137 | if (n == 0) | 150 | if (n == 0) |
138 | break; | 151 | break; |
139 | if (n == bs) | 152 | if (n == bs) |
diff --git a/include/usage.h b/include/usage.h index ad34dfcff..d0f3dfc99 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -228,7 +228,7 @@ | |||
228 | 228 | ||
229 | #define dd_trivial_usage \ | 229 | #define dd_trivial_usage \ |
230 | "[if=FILE] [of=FILE] [bs=N] [count=N] [skip=N]\n" \ | 230 | "[if=FILE] [of=FILE] [bs=N] [count=N] [skip=N]\n" \ |
231 | "\t [seek=N] [conv=notrunc|sync]" | 231 | "\t [seek=N] [conv=notrunc|noerror|sync]" |
232 | #define dd_full_usage \ | 232 | #define dd_full_usage \ |
233 | "Copy a file, converting and formatting according to options\n\n" \ | 233 | "Copy a file, converting and formatting according to options\n\n" \ |
234 | "\tif=FILE\t\tread from FILE instead of stdin\n" \ | 234 | "\tif=FILE\t\tread from FILE instead of stdin\n" \ |
@@ -238,6 +238,7 @@ | |||
238 | "\tskip=N\t\tskip N input blocks\n" \ | 238 | "\tskip=N\t\tskip N input blocks\n" \ |
239 | "\tseek=N\t\tskip N output blocks\n" \ | 239 | "\tseek=N\t\tskip N output blocks\n" \ |
240 | "\tconv=notrunc\tdon't truncate output file\n" \ | 240 | "\tconv=notrunc\tdon't truncate output file\n" \ |
241 | "\tconv=noerror\tcontinue after read errors\n" \ | ||
241 | "\tconv=sync\tpad blocks with zeros\n" \ | 242 | "\tconv=sync\tpad blocks with zeros\n" \ |
242 | "\n" \ | 243 | "\n" \ |
243 | "Numbers may be suffixed by c (x1), w (x2), b (x512), kD (x1000), k (x1024),\n" \ | 244 | "Numbers may be suffixed by c (x1), w (x2), b (x512), kD (x1000), k (x1024),\n" \ |