aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2009-04-22 22:29:41 +1000
committerNguyễn Thái Ngọc Duy <pclouds@gmail.com>2009-04-23 04:44:37 +1000
commit86142001d8ef967528d5f9f4b585e85936c9c228 (patch)
treec2013f5eb69daec392ac56b263c4373ea2199617
parentd90250d75cd624a6dc0156f98952ff418379948a (diff)
downloadbusybox-w32-86142001d8ef967528d5f9f4b585e85936c9c228.tar.gz
busybox-w32-86142001d8ef967528d5f9f4b585e85936c9c228.tar.bz2
busybox-w32-86142001d8ef967528d5f9f4b585e85936c9c228.zip
coreutils/dd: support /dev/zero
-rw-r--r--coreutils/dd.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index ba3afeae8..5b0119d25 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -109,6 +109,7 @@ int dd_main(int argc, char **argv)
109 ssize_t n, w; 109 ssize_t n, w;
110 off_t seek = 0, skip = 0, count = OFF_T_MAX; 110 off_t seek = 0, skip = 0, count = OFF_T_MAX;
111 int ifd, ofd; 111 int ifd, ofd;
112 int devzero = 0;
112 const char *infile = NULL, *outfile = NULL; 113 const char *infile = NULL, *outfile = NULL;
113 char *ibuf, *obuf; 114 char *ibuf, *obuf;
114 115
@@ -211,7 +212,13 @@ int dd_main(int argc, char **argv)
211 obuf = xmalloc(obs); 212 obuf = xmalloc(obs);
212 } 213 }
213 if (infile != NULL) 214 if (infile != NULL)
214 ifd = xopen(infile, O_RDONLY); 215 if (!strcmp(infile, "/dev/zero")) {
216 flags |= NOERROR;
217 devzero = 1;
218 ifd = -1;
219 }
220 else
221 ifd = xopen(infile, O_RDONLY);
215 else { 222 else {
216 ifd = STDIN_FILENO; 223 ifd = STDIN_FILENO;
217 infile = bb_msg_standard_input; 224 infile = bb_msg_standard_input;
@@ -262,7 +269,8 @@ int dd_main(int argc, char **argv)
262 if (n < 0) { 269 if (n < 0) {
263 if (flags & NOERROR) { 270 if (flags & NOERROR) {
264 n = ibs; 271 n = ibs;
265 bb_perror_msg("%s", infile); 272 if (!devzero)
273 bb_perror_msg("%s", infile);
266 } else 274 } else
267 goto die_infile; 275 goto die_infile;
268 } 276 }
@@ -302,7 +310,7 @@ int dd_main(int argc, char **argv)
302 if (w > 0) 310 if (w > 0)
303 G.out_part++; 311 G.out_part++;
304 } 312 }
305 if (close(ifd) < 0) { 313 if (!devzero && close(ifd) < 0) {
306die_infile: 314die_infile:
307 bb_perror_msg_and_die("%s", infile); 315 bb_perror_msg_and_die("%s", infile);
308 } 316 }