summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen2002-04-27 01:31:43 +0000
committerEric Andersen2002-04-27 01:31:43 +0000
commitef38b392627b31abf6b99273311d2a155023e73a (patch)
tree8a9352d2558a97ccbc65490a28d66ea39bc4347e
parentaba75460e4ca8415e9dd3b07ed3511126724dbd9 (diff)
downloadbusybox-ef38b392627b31abf6b99273311d2a155023e73a.zip
busybox-ef38b392627b31abf6b99273311d2a155023e73a.tar.gz
Support noerror option
-rw-r--r--coreutils/dd.c19
-rw-r--r--include/usage.h3
2 files changed, 18 insertions, 4 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 09e6ccc..fb78d53 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -46,7 +46,7 @@ static const struct suffix_mult dd_suffixes[] = {
int dd_main(int argc, char **argv)
{
- int i, ifd, ofd, oflag, sync_flag = FALSE, trunc = TRUE;
+ int i, ifd, ofd, oflag, sync_flag = FALSE, trunc = TRUE, noerror = FALSE;
size_t in_full = 0, in_part = 0, out_full = 0, out_part = 0;
size_t bs = 512, count = -1;
ssize_t n;
@@ -75,6 +75,9 @@ int dd_main(int argc, char **argv)
} else if (strncmp("sync", buf, 4) == 0) {
sync_flag = TRUE;
buf += 4;
+ } else if (strncmp("noerror", buf, 7) == 0) {
+ noerror = TRUE;
+ buf += 7;
} else {
error_msg_and_die("invalid conversion `%s'", argv[i]+5);
}
@@ -131,9 +134,19 @@ int dd_main(int argc, char **argv)
}
while (in_full + in_part != count) {
+ if (noerror) {
+ /* Pre-zero the buffer when doing the noerror thing */
+ memset(buf, '\0', bs);
+ }
n = safe_read(ifd, buf, bs);
- if (n < 0)
- perror_msg_and_die("%s", infile);
+ if (n < 0) {
+ if (noerror) {
+ n = bs;
+ perror_msg("%s", infile);
+ } else {
+ perror_msg_and_die("%s", infile);
+ }
+ }
if (n == 0)
break;
if (n == bs)
diff --git a/include/usage.h b/include/usage.h
index ad34dfc..d0f3dfc 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -228,7 +228,7 @@
#define dd_trivial_usage \
"[if=FILE] [of=FILE] [bs=N] [count=N] [skip=N]\n" \
- "\t [seek=N] [conv=notrunc|sync]"
+ "\t [seek=N] [conv=notrunc|noerror|sync]"
#define dd_full_usage \
"Copy a file, converting and formatting according to options\n\n" \
"\tif=FILE\t\tread from FILE instead of stdin\n" \
@@ -238,6 +238,7 @@
"\tskip=N\t\tskip N input blocks\n" \
"\tseek=N\t\tskip N output blocks\n" \
"\tconv=notrunc\tdon't truncate output file\n" \
+ "\tconv=noerror\tcontinue after read errors\n" \
"\tconv=sync\tpad blocks with zeros\n" \
"\n" \
"Numbers may be suffixed by c (x1), w (x2), b (x512), kD (x1000), k (x1024),\n" \