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 /coreutils/dd.c | |
parent | aba75460e4ca8415e9dd3b07ed3511126724dbd9 (diff) | |
download | busybox-w32-ef38b392627b31abf6b99273311d2a155023e73a.tar.gz busybox-w32-ef38b392627b31abf6b99273311d2a155023e73a.tar.bz2 busybox-w32-ef38b392627b31abf6b99273311d2a155023e73a.zip |
Support noerror option
Diffstat (limited to 'coreutils/dd.c')
-rw-r--r-- | coreutils/dd.c | 19 |
1 files changed, 16 insertions, 3 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) |