dd: move suffix struct to xatonum.c
authorAri Sundholm <ari@tuxera.com>
Wed, 4 Mar 2015 16:46:48 +0000 (18:46 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 22 Mar 2015 16:41:04 +0000 (17:41 +0100)
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>
coreutils/dd.c
include/libbb.h
libbb/xatonum.c

index 30249707421f1268148b3503f777ef2be18f88c1..53a843ca0c90091021da812d050e54dec4ecd12c 100644 (file)
@@ -99,25 +99,6 @@ enum {
        ofd = STDOUT_FILENO,
 };
 
-static const struct suffix_mult dd_suffixes[] = {
-       { "c", 1 },
-       { "w", 2 },
-       { "b", 512 },
-       { "kB", 1000 },
-       { "kD", 1000 },
-       { "k", 1024 },
-       { "K", 1024 },  /* compat with coreutils dd (it also accepts KB and KD, TODO?) */
-       { "MB", 1000000 },
-       { "MD", 1000000 },
-       { "M", 1024*1024 },
-       { "GB", 1000000000 },
-       { "GD", 1000000000 },
-       { "G", 1024*1024*1024 },
-       /* "D" suffix for decimal is not in coreutils manpage, looks like it's deprecated */
-       /* coreutils also understands TPEZY suffixes for tera- and so on, with B suffix for decimal */
-       { "", 0 }
-};
-
 struct globals {
        off_t out_full, out_part, in_full, in_part;
 #if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
@@ -326,11 +307,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
 #if ENABLE_FEATURE_DD_IBS_OBS
                if (what == OP_ibs) {
                        /* Must fit into positive ssize_t */
-                       ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
+                       ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
                        /*continue;*/
                }
                if (what == OP_obs) {
-                       obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
+                       obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
                        /*continue;*/
                }
                if (what == OP_conv) {
@@ -356,22 +337,22 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
                }
 #endif
                if (what == OP_bs) {
-                       ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
+                       ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
                        obs = ibs;
                        /*continue;*/
                }
                /* These can be large: */
                if (what == OP_count) {
                        G.flags |= FLAG_COUNT;
-                       count = XATOU_SFX(val, dd_suffixes);
+                       count = XATOU_SFX(val, cwbkMG_suffixes);
                        /*continue;*/
                }
                if (what == OP_seek) {
-                       seek = XATOU_SFX(val, dd_suffixes);
+                       seek = XATOU_SFX(val, cwbkMG_suffixes);
                        /*continue;*/
                }
                if (what == OP_skip) {
-                       skip = XATOU_SFX(val, dd_suffixes);
+                       skip = XATOU_SFX(val, cwbkMG_suffixes);
                        /*continue;*/
                }
                if (what == OP_if) {
index c97df604733248b0bb1fdbbdc14013f4564ea49f..9550c058964aac42a4bd574f0f7ddd62f0cda9bc 100644 (file)
@@ -862,6 +862,7 @@ struct suffix_mult {
 };
 extern const struct suffix_mult bkm_suffixes[];
 #define km_suffixes (bkm_suffixes + 1)
+extern const struct suffix_mult cwbkMG_suffixes[];
 
 #include "xatonum.h"
 /* Specialized: */
index 6f4e023bbc166de84cadcc6e0bc38afdc8ff325d..19b54fb0c6600acf3dd4dcc5c21b451aabae2d83 100644 (file)
@@ -75,3 +75,22 @@ const struct suffix_mult bkm_suffixes[] = {
        { "m", 1024*1024 },
        { "", 0 }
 };
+
+const struct suffix_mult cwbkMG_suffixes[] = {
+       { "c", 1 },
+       { "w", 2 },
+       { "b", 512 },
+       { "kB", 1000 },
+       { "kD", 1000 },
+       { "k", 1024 },
+       { "K", 1024 },  /* compat with coreutils dd (it also accepts KB and KD, TODO?) */
+       { "MB", 1000000 },
+       { "MD", 1000000 },
+       { "M", 1024*1024 },
+       { "GB", 1000000000 },
+       { "GD", 1000000000 },
+       { "G", 1024*1024*1024 },
+       /* "D" suffix for decimal is not in coreutils manpage, looks like it's deprecated */
+       /* coreutils also understands TPEZY suffixes for tera- and so on, with B suffix for decimal */
+       { "", 0 }
+};