aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-08-20 12:08:46 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2013-08-20 12:08:46 +0200
commit4502bb1f21d39a74cc77e92935ef1767c2f9bf14 (patch)
tree8a2fc922070b3e86fc64406789670e87e7ddae78 /coreutils
parent5b9910f0a4a1b7976c46e6f849aaa263180e5521 (diff)
downloadbusybox-w32-4502bb1f21d39a74cc77e92935ef1767c2f9bf14.tar.gz
busybox-w32-4502bb1f21d39a74cc77e92935ef1767c2f9bf14.tar.bz2
busybox-w32-4502bb1f21d39a74cc77e92935ef1767c2f9bf14.zip
dd: code shrink
function old new delta dd_main 1001 961 -40 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/dd.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index e22938859..bbd117b77 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -203,10 +203,17 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
203#endif 203#endif
204 }; 204 };
205 smallint exitcode = EXIT_FAILURE; 205 smallint exitcode = EXIT_FAILURE;
206 size_t ibs = 512, obs = 512;
207 int i; 206 int i;
208 char *ibuf, *obuf; 207 size_t ibs = 512;
209 /* And these are all zeroed at once! */ 208 char *ibuf;
209#if ENABLE_FEATURE_DD_IBS_OBS
210 size_t obs = 512;
211 char *obuf;
212#else
213# define obs ibs
214# define obuf ibuf
215#endif
216 /* These are all zeroed at once! */
210 struct { 217 struct {
211 int flags; 218 int flags;
212 size_t oc; 219 size_t oc;
@@ -260,6 +267,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
260 } 267 }
261 if (what == OP_conv) { 268 if (what == OP_conv) {
262 while (1) { 269 while (1) {
270 int n;
263 /* find ',', replace them with NUL so we can use val for 271 /* find ',', replace them with NUL so we can use val for
264 * index_in_strings() without copying. 272 * index_in_strings() without copying.
265 * We rely on val being non-null, else strchr would fault. 273 * We rely on val being non-null, else strchr would fault.
@@ -267,20 +275,21 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
267 arg = strchr(val, ','); 275 arg = strchr(val, ',');
268 if (arg) 276 if (arg)
269 *arg = '\0'; 277 *arg = '\0';
270 what = index_in_strings(conv_words, val); 278 n = index_in_strings(conv_words, val);
271 if (what < 0) 279 if (n < 0)
272 bb_error_msg_and_die(bb_msg_invalid_arg, val, "conv"); 280 bb_error_msg_and_die(bb_msg_invalid_arg, val, "conv");
273 flags |= (1 << what); 281 flags |= (1 << n);
274 if (!arg) /* no ',' left, so this was the last specifier */ 282 if (!arg) /* no ',' left, so this was the last specifier */
275 break; 283 break;
276 /* *arg = ','; - to preserve ps listing? */ 284 /* *arg = ','; - to preserve ps listing? */
277 val = arg + 1; /* skip this keyword and ',' */ 285 val = arg + 1; /* skip this keyword and ',' */
278 } 286 }
279 continue; /* we trashed 'what', can't fall through */ 287 /*continue;*/
280 } 288 }
281#endif 289#endif
282 if (what == OP_bs) { 290 if (what == OP_bs) {
283 ibs = obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes); 291 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
292 obs = ibs;
284 /*continue;*/ 293 /*continue;*/
285 } 294 }
286 /* These can be large: */ 295 /* These can be large: */
@@ -308,11 +317,14 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
308 } /* end of "for (argv[i])" */ 317 } /* end of "for (argv[i])" */
309 318
310//XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever 319//XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever
311 ibuf = obuf = xmalloc(ibs); 320 ibuf = xmalloc(ibs);
321 obuf = ibuf;
322#if ENABLE_FEATURE_DD_IBS_OBS
312 if (ibs != obs) { 323 if (ibs != obs) {
313 flags |= FLAG_TWOBUFS; 324 flags |= FLAG_TWOBUFS;
314 obuf = xmalloc(obs); 325 obuf = xmalloc(obs);
315 } 326 }
327#endif
316 328
317#if ENABLE_FEATURE_DD_SIGNAL_HANDLING 329#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
318 signal_SA_RESTART_empty_mask(SIGUSR1, dd_output_status); 330 signal_SA_RESTART_empty_mask(SIGUSR1, dd_output_status);
@@ -321,12 +333,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
321 G.begin_time_us = monotonic_us(); 333 G.begin_time_us = monotonic_us();
322#endif 334#endif
323 335
324 if (infile != NULL) 336 if (infile) {
325 xmove_fd(xopen(infile, O_RDONLY), ifd); 337 xmove_fd(xopen(infile, O_RDONLY), ifd);
326 else { 338 } else {
327 infile = bb_msg_standard_input; 339 infile = bb_msg_standard_input;
328 } 340 }
329 if (outfile != NULL) { 341 if (outfile) {
330 int oflag = O_WRONLY | O_CREAT; 342 int oflag = O_WRONLY | O_CREAT;
331 343
332 if (!seek && !(flags & FLAG_NOTRUNC)) 344 if (!seek && !(flags & FLAG_NOTRUNC))