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 3d1ba2ee6..8c144cfd2 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -294,6 +294,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
294 | #endif | 294 | #endif |
295 | }; | 295 | }; |
296 | smallint exitcode = EXIT_FAILURE; | 296 | smallint exitcode = EXIT_FAILURE; |
297 | int devzero = 0; | ||
297 | int i; | 298 | int i; |
298 | size_t ibs = 512; | 299 | size_t ibs = 512; |
299 | char *ibuf; | 300 | char *ibuf; |
@@ -420,7 +421,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
420 | #endif | 421 | #endif |
421 | 422 | ||
422 | if (infile) { | 423 | if (infile) { |
423 | xmove_fd(xopen(infile, O_RDONLY), ifd); | 424 | if (ENABLE_PLATFORM_MINGW32 && !strcmp(infile, "/dev/zero")) { |
425 | G.flags |= FLAG_NOERROR; | ||
426 | devzero = 1; | ||
427 | } else { | ||
428 | xmove_fd(xopen(infile, O_RDONLY), ifd); | ||
429 | } | ||
424 | } else { | 430 | } else { |
425 | infile = bb_msg_standard_input; | 431 | infile = bb_msg_standard_input; |
426 | } | 432 | } |
@@ -447,7 +453,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
447 | } else { | 453 | } else { |
448 | outfile = bb_msg_standard_output; | 454 | outfile = bb_msg_standard_output; |
449 | } | 455 | } |
450 | if (skip) { | 456 | if (skip && !devzero) { |
451 | size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs; | 457 | size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs; |
452 | if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) { | 458 | if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) { |
453 | do { | 459 | do { |
@@ -467,7 +473,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
467 | while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) { | 473 | while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) { |
468 | ssize_t n; | 474 | ssize_t n; |
469 | 475 | ||
470 | n = safe_read(ifd, ibuf, ibs); | 476 | if (devzero) { |
477 | memset(ibuf, 0, ibs); | ||
478 | n = ibs; | ||
479 | } | ||
480 | else | ||
481 | n = safe_read(ifd, ibuf, ibs); | ||
471 | if (n == 0) | 482 | if (n == 0) |
472 | break; | 483 | break; |
473 | if (n < 0) { | 484 | if (n < 0) { |
@@ -543,7 +554,8 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
543 | if (write_and_stats(obuf, oc, obs, outfile)) | 554 | if (write_and_stats(obuf, oc, obs, outfile)) |
544 | goto out_status; | 555 | goto out_status; |
545 | } | 556 | } |
546 | if (close(ifd) < 0) { | 557 | |
558 | if (!devzero && close(ifd) < 0) { | ||
547 | die_infile: | 559 | die_infile: |
548 | bb_simple_perror_msg_and_die(infile); | 560 | bb_simple_perror_msg_and_die(infile); |
549 | } | 561 | } |