aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAri Sundholm <ari@tuxera.com>2015-03-04 18:46:48 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2015-03-22 17:41:04 +0100
commit8893023ba27ea87b12a333960271c9f86cdebf7b (patch)
tree09664462b0bb252b1227b689a2240e02ec1b0f5b
parent92edab1aa6eae45ac8fa0cec8c8df9a47f547300 (diff)
downloadbusybox-w32-8893023ba27ea87b12a333960271c9f86cdebf7b.tar.gz
busybox-w32-8893023ba27ea87b12a333960271c9f86cdebf7b.tar.bz2
busybox-w32-8893023ba27ea87b12a333960271c9f86cdebf7b.zip
dd: move suffix struct to xatonum.c
This way it can be used by other applets without duplication. Signed-off-by: Ari Sundholm <ari@tuxera.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/dd.c31
-rw-r--r--include/libbb.h1
-rw-r--r--libbb/xatonum.c19
3 files changed, 26 insertions, 25 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 302497074..53a843ca0 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -99,25 +99,6 @@ enum {
99 ofd = STDOUT_FILENO, 99 ofd = STDOUT_FILENO,
100}; 100};
101 101
102static const struct suffix_mult dd_suffixes[] = {
103 { "c", 1 },
104 { "w", 2 },
105 { "b", 512 },
106 { "kB", 1000 },
107 { "kD", 1000 },
108 { "k", 1024 },
109 { "K", 1024 }, /* compat with coreutils dd (it also accepts KB and KD, TODO?) */
110 { "MB", 1000000 },
111 { "MD", 1000000 },
112 { "M", 1024*1024 },
113 { "GB", 1000000000 },
114 { "GD", 1000000000 },
115 { "G", 1024*1024*1024 },
116 /* "D" suffix for decimal is not in coreutils manpage, looks like it's deprecated */
117 /* coreutils also understands TPEZY suffixes for tera- and so on, with B suffix for decimal */
118 { "", 0 }
119};
120
121struct globals { 102struct globals {
122 off_t out_full, out_part, in_full, in_part; 103 off_t out_full, out_part, in_full, in_part;
123#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE 104#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
@@ -326,11 +307,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
326#if ENABLE_FEATURE_DD_IBS_OBS 307#if ENABLE_FEATURE_DD_IBS_OBS
327 if (what == OP_ibs) { 308 if (what == OP_ibs) {
328 /* Must fit into positive ssize_t */ 309 /* Must fit into positive ssize_t */
329 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes); 310 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
330 /*continue;*/ 311 /*continue;*/
331 } 312 }
332 if (what == OP_obs) { 313 if (what == OP_obs) {
333 obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes); 314 obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
334 /*continue;*/ 315 /*continue;*/
335 } 316 }
336 if (what == OP_conv) { 317 if (what == OP_conv) {
@@ -356,22 +337,22 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
356 } 337 }
357#endif 338#endif
358 if (what == OP_bs) { 339 if (what == OP_bs) {
359 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes); 340 ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
360 obs = ibs; 341 obs = ibs;
361 /*continue;*/ 342 /*continue;*/
362 } 343 }
363 /* These can be large: */ 344 /* These can be large: */
364 if (what == OP_count) { 345 if (what == OP_count) {
365 G.flags |= FLAG_COUNT; 346 G.flags |= FLAG_COUNT;
366 count = XATOU_SFX(val, dd_suffixes); 347 count = XATOU_SFX(val, cwbkMG_suffixes);
367 /*continue;*/ 348 /*continue;*/
368 } 349 }
369 if (what == OP_seek) { 350 if (what == OP_seek) {
370 seek = XATOU_SFX(val, dd_suffixes); 351 seek = XATOU_SFX(val, cwbkMG_suffixes);
371 /*continue;*/ 352 /*continue;*/
372 } 353 }
373 if (what == OP_skip) { 354 if (what == OP_skip) {
374 skip = XATOU_SFX(val, dd_suffixes); 355 skip = XATOU_SFX(val, cwbkMG_suffixes);
375 /*continue;*/ 356 /*continue;*/
376 } 357 }
377 if (what == OP_if) { 358 if (what == OP_if) {
diff --git a/include/libbb.h b/include/libbb.h
index c97df6047..9550c0589 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -862,6 +862,7 @@ struct suffix_mult {
862}; 862};
863extern const struct suffix_mult bkm_suffixes[]; 863extern const struct suffix_mult bkm_suffixes[];
864#define km_suffixes (bkm_suffixes + 1) 864#define km_suffixes (bkm_suffixes + 1)
865extern const struct suffix_mult cwbkMG_suffixes[];
865 866
866#include "xatonum.h" 867#include "xatonum.h"
867/* Specialized: */ 868/* Specialized: */
diff --git a/libbb/xatonum.c b/libbb/xatonum.c
index 6f4e023bb..19b54fb0c 100644
--- a/libbb/xatonum.c
+++ b/libbb/xatonum.c
@@ -75,3 +75,22 @@ const struct suffix_mult bkm_suffixes[] = {
75 { "m", 1024*1024 }, 75 { "m", 1024*1024 },
76 { "", 0 } 76 { "", 0 }
77}; 77};
78
79const struct suffix_mult cwbkMG_suffixes[] = {
80 { "c", 1 },
81 { "w", 2 },
82 { "b", 512 },
83 { "kB", 1000 },
84 { "kD", 1000 },
85 { "k", 1024 },
86 { "K", 1024 }, /* compat with coreutils dd (it also accepts KB and KD, TODO?) */
87 { "MB", 1000000 },
88 { "MD", 1000000 },
89 { "M", 1024*1024 },
90 { "GB", 1000000000 },
91 { "GD", 1000000000 },
92 { "G", 1024*1024*1024 },
93 /* "D" suffix for decimal is not in coreutils manpage, looks like it's deprecated */
94 /* coreutils also understands TPEZY suffixes for tera- and so on, with B suffix for decimal */
95 { "", 0 }
96};