diff options
Diffstat (limited to 'coreutils/dd.c')
-rw-r--r-- | coreutils/dd.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index 2838f6341..db61f665e 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -203,6 +203,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
203 | #endif | 203 | #endif |
204 | }; | 204 | }; |
205 | smallint exitcode = EXIT_FAILURE; | 205 | smallint exitcode = EXIT_FAILURE; |
206 | int devzero = 0; | ||
206 | int i; | 207 | int i; |
207 | size_t ibs = 512; | 208 | size_t ibs = 512; |
208 | char *ibuf; | 209 | char *ibuf; |
@@ -334,7 +335,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
334 | #endif | 335 | #endif |
335 | 336 | ||
336 | if (infile) { | 337 | if (infile) { |
337 | xmove_fd(xopen(infile, O_RDONLY), ifd); | 338 | if (ENABLE_PLATFORM_MINGW32 && !strcmp(infile, "/dev/zero")) { |
339 | flags |= FLAG_NOERROR; | ||
340 | devzero = 1; | ||
341 | } else { | ||
342 | xmove_fd(xopen(infile, O_RDONLY), ifd); | ||
343 | } | ||
338 | } else { | 344 | } else { |
339 | infile = bb_msg_standard_input; | 345 | infile = bb_msg_standard_input; |
340 | } | 346 | } |
@@ -361,7 +367,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
361 | } else { | 367 | } else { |
362 | outfile = bb_msg_standard_output; | 368 | outfile = bb_msg_standard_output; |
363 | } | 369 | } |
364 | if (skip) { | 370 | if (skip && !devzero) { |
365 | if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) { | 371 | if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) { |
366 | do { | 372 | do { |
367 | ssize_t n = safe_read(ifd, ibuf, ibs); | 373 | ssize_t n = safe_read(ifd, ibuf, ibs); |
@@ -380,7 +386,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
380 | while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) { | 386 | while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) { |
381 | ssize_t n; | 387 | ssize_t n; |
382 | 388 | ||
383 | n = safe_read(ifd, ibuf, ibs); | 389 | if (devzero) { |
390 | memset(ibuf, 0, ibs); | ||
391 | n = ibs; | ||
392 | } | ||
393 | else | ||
394 | n = safe_read(ifd, ibuf, ibs); | ||
384 | if (n == 0) | 395 | if (n == 0) |
385 | break; | 396 | break; |
386 | if (n < 0) { | 397 | if (n < 0) { |
@@ -456,7 +467,8 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
456 | if (write_and_stats(obuf, oc, obs, outfile)) | 467 | if (write_and_stats(obuf, oc, obs, outfile)) |
457 | goto out_status; | 468 | goto out_status; |
458 | } | 469 | } |
459 | if (close(ifd) < 0) { | 470 | |
471 | if (!devzero && close(ifd) < 0) { | ||
460 | die_infile: | 472 | die_infile: |
461 | bb_simple_perror_msg_and_die(infile); | 473 | bb_simple_perror_msg_and_die(infile); |
462 | } | 474 | } |