aboutsummaryrefslogtreecommitdiff
path: root/coreutils/dd.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/dd.c')
-rw-r--r--coreutils/dd.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 43545c010..f7f1c9564 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -293,6 +293,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
293#endif 293#endif
294 }; 294 };
295 smallint exitcode = EXIT_FAILURE; 295 smallint exitcode = EXIT_FAILURE;
296 int devzero = 0;
296 int i; 297 int i;
297 size_t ibs = 512; 298 size_t ibs = 512;
298 char *ibuf; 299 char *ibuf;
@@ -419,7 +420,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
419#endif 420#endif
420 421
421 if (infile) { 422 if (infile) {
422 xmove_fd(xopen(infile, O_RDONLY), ifd); 423 if (ENABLE_PLATFORM_MINGW32 && !strcmp(infile, "/dev/zero")) {
424 G.flags |= FLAG_NOERROR;
425 devzero = 1;
426 } else {
427 xmove_fd(xopen(infile, O_RDONLY), ifd);
428 }
423 } else { 429 } else {
424 infile = bb_msg_standard_input; 430 infile = bb_msg_standard_input;
425 } 431 }
@@ -446,7 +452,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
446 } else { 452 } else {
447 outfile = bb_msg_standard_output; 453 outfile = bb_msg_standard_output;
448 } 454 }
449 if (skip) { 455 if (skip && !devzero) {
450 size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs; 456 size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs;
451 if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) { 457 if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) {
452 do { 458 do {
@@ -466,7 +472,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
466 while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) { 472 while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
467 ssize_t n; 473 ssize_t n;
468 474
469 n = safe_read(ifd, ibuf, ibs); 475 if (devzero) {
476 memset(ibuf, 0, ibs);
477 n = ibs;
478 }
479 else
480 n = safe_read(ifd, ibuf, ibs);
470 if (n == 0) 481 if (n == 0)
471 break; 482 break;
472 if (n < 0) { 483 if (n < 0) {
@@ -542,7 +553,8 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
542 if (write_and_stats(obuf, oc, obs, outfile)) 553 if (write_and_stats(obuf, oc, obs, outfile))
543 goto out_status; 554 goto out_status;
544 } 555 }
545 if (close(ifd) < 0) { 556
557 if (!devzero && close(ifd) < 0) {
546 die_infile: 558 die_infile:
547 bb_simple_perror_msg_and_die(infile); 559 bb_simple_perror_msg_and_die(infile);
548 } 560 }