aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-02-22 11:57:26 +0000
committerRon Yorston <rmy@pobox.com>2018-02-22 11:57:26 +0000
commit227c119c93f8acd299e4e3c8b9601e67f000fb53 (patch)
tree988182576406d3eecd1e36b5d28577a0a5feb387 /coreutils
parent4e6d0dc9476e5cf43ff0bc5e66a54d812ddb4225 (diff)
downloadbusybox-w32-227c119c93f8acd299e4e3c8b9601e67f000fb53.tar.gz
busybox-w32-227c119c93f8acd299e4e3c8b9601e67f000fb53.tar.bz2
busybox-w32-227c119c93f8acd299e4e3c8b9601e67f000fb53.zip
dd: use new device handling to implement /dev/zero and /dev/urandom
Replace internal support for /dev/zero with the newly introduced device handling in open/read. This reduces the differences between busybox-w32 and upstream.
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/dd.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 178576752..8158a1e57 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -300,7 +300,6 @@ 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;
304 int i; 303 int i;
305 size_t ibs = 512; 304 size_t ibs = 512;
306 char *ibuf; 305 char *ibuf;
@@ -427,12 +426,15 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
427#endif 426#endif
428 427
429 if (infile) { 428 if (infile) {
430 if (ENABLE_PLATFORM_MINGW32 && !strcmp(infile, "/dev/zero")) { 429 xmove_fd(xopen(infile, O_RDONLY), ifd);
431 G.flags |= FLAG_NOERROR; 430#if ENABLE_PLATFORM_MINGW32
432 devzero = 1; 431 if (!strcmp(infile, "/dev/zero")) {
433 } else { 432 mingw_read_zero(ifd);
434 xmove_fd(xopen(infile, O_RDONLY), ifd); 433 }
434 else if (!strcmp(infile, "/dev/urandom")) {
435 mingw_read_random(ifd);
435 } 436 }
437#endif
436 } else { 438 } else {
437 infile = bb_msg_standard_input; 439 infile = bb_msg_standard_input;
438 } 440 }
@@ -459,7 +461,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
459 } else { 461 } else {
460 outfile = bb_msg_standard_output; 462 outfile = bb_msg_standard_output;
461 } 463 }
462 if (skip && !devzero) { 464 if (skip) {
463 size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs; 465 size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs;
464 if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) { 466 if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) {
465 do { 467 do {
@@ -485,11 +487,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
485 while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) { 487 while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
486 ssize_t n; 488 ssize_t n;
487 489
488 if (devzero) {
489 memset(ibuf, 0, ibs);
490 n = ibs;
491 }
492 else
493#if ENABLE_FEATURE_DD_IBS_OBS 490#if ENABLE_FEATURE_DD_IBS_OBS
494 if (G.flags & FLAG_FULLBLOCK) 491 if (G.flags & FLAG_FULLBLOCK)
495 n = full_read(ifd, ibuf, ibs); 492 n = full_read(ifd, ibuf, ibs);
@@ -572,7 +569,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
572 goto out_status; 569 goto out_status;
573 } 570 }
574 571
575 if (!devzero && close(ifd) < 0) { 572 if (close(ifd) < 0) {
576 die_infile: 573 die_infile:
577 bb_simple_perror_msg_and_die(infile); 574 bb_simple_perror_msg_and_die(infile);
578 } 575 }