aboutsummaryrefslogtreecommitdiff
path: root/coreutils/dd.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/dd.c')
-rw-r--r--coreutils/dd.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 0f130bcad..178576752 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -300,6 +300,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
300#endif 300#endif
301 }; 301 };
302 smallint exitcode = EXIT_FAILURE; 302 smallint exitcode = EXIT_FAILURE;
303 int devzero = 0;
303 int i; 304 int i;
304 size_t ibs = 512; 305 size_t ibs = 512;
305 char *ibuf; 306 char *ibuf;
@@ -353,11 +354,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
353#if ENABLE_FEATURE_DD_IBS_OBS 354#if ENABLE_FEATURE_DD_IBS_OBS
354 if (what == OP_ibs) { 355 if (what == OP_ibs) {
355 /* Must fit into positive ssize_t */ 356 /* Must fit into positive ssize_t */
356 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); 357 ibs = xatoul_range_sfx(val, 1, ULONG_MAX/2, cwbkMG_suffixes);
357 /*continue;*/ 358 /*continue;*/
358 } 359 }
359 if (what == OP_obs) { 360 if (what == OP_obs) {
360 obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); 361 obs = xatoul_range_sfx(val, 1, ULONG_MAX/2, cwbkMG_suffixes);
361 /*continue;*/ 362 /*continue;*/
362 } 363 }
363 if (what == OP_conv) { 364 if (what == OP_conv) {
@@ -370,7 +371,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
370 } 371 }
371#endif 372#endif
372 if (what == OP_bs) { 373 if (what == OP_bs) {
373 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes); 374 ibs = xatoul_range_sfx(val, 1, ULONG_MAX/2, cwbkMG_suffixes);
374 obs = ibs; 375 obs = ibs;
375 /*continue;*/ 376 /*continue;*/
376 } 377 }
@@ -426,7 +427,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
426#endif 427#endif
427 428
428 if (infile) { 429 if (infile) {
429 xmove_fd(xopen(infile, O_RDONLY), ifd); 430 if (ENABLE_PLATFORM_MINGW32 && !strcmp(infile, "/dev/zero")) {
431 G.flags |= FLAG_NOERROR;
432 devzero = 1;
433 } else {
434 xmove_fd(xopen(infile, O_RDONLY), ifd);
435 }
430 } else { 436 } else {
431 infile = bb_msg_standard_input; 437 infile = bb_msg_standard_input;
432 } 438 }
@@ -453,7 +459,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
453 } else { 459 } else {
454 outfile = bb_msg_standard_output; 460 outfile = bb_msg_standard_output;
455 } 461 }
456 if (skip) { 462 if (skip && !devzero) {
457 size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs; 463 size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs;
458 if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) { 464 if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) {
459 do { 465 do {
@@ -478,6 +484,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
478 484
479 while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) { 485 while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
480 ssize_t n; 486 ssize_t n;
487
488 if (devzero) {
489 memset(ibuf, 0, ibs);
490 n = ibs;
491 }
492 else
481#if ENABLE_FEATURE_DD_IBS_OBS 493#if ENABLE_FEATURE_DD_IBS_OBS
482 if (G.flags & FLAG_FULLBLOCK) 494 if (G.flags & FLAG_FULLBLOCK)
483 n = full_read(ifd, ibuf, ibs); 495 n = full_read(ifd, ibuf, ibs);
@@ -559,7 +571,8 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
559 if (write_and_stats(obuf, oc, obs, outfile)) 571 if (write_and_stats(obuf, oc, obs, outfile))
560 goto out_status; 572 goto out_status;
561 } 573 }
562 if (close(ifd) < 0) { 574
575 if (!devzero && close(ifd) < 0) {
563 die_infile: 576 die_infile:
564 bb_simple_perror_msg_and_die(infile); 577 bb_simple_perror_msg_and_die(infile);
565 } 578 }