Replying to myself... On Tue, 2015-03-03 at 19:22 +0200, Ari Sundholm wrote: > On Tue, 2015-03-03 at 17:02 +0000, Isaac Dunham wrote: > > On Tue, Mar 03, 2015 at 06:11:55PM +0200, Ari Sundholm wrote: > > > I wrote this for my own purposes and cleaned it up in hopes it is useful. > > > > > > Signed-off-by: Ari Sundholm <[email protected]> > > > --- > > > coreutils/truncate.c | 92 > > > ++++++++++++++++++++++++++++++++++++++++++++++++++++ > > > 1 file changed, 92 insertions(+) > > > create mode 100644 coreutils/truncate.c > > > > > > diff --git a/coreutils/truncate.c b/coreutils/truncate.c > > > new file mode 100644 > > > index 0000000..f997cd2 > > > --- /dev/null > > > +++ b/coreutils/truncate.c > > > > > +static const struct suffix_mult truncate_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 } > > > +}; > > > > Was this copy-pasted from coreutils/dd.c? > > The bloat could be reduced by making it shared between dd and truncate; > > if my math is right, this table is at least 87 bytes. > > > > Yes, it is copy-pasted from dd.c. When writing this applet I did briefly > think of having these shared somewhere, but eventually didn't do > anything about it. > > It would probably be a good idea indeed to create a common list of > filesize suffixes and use it in applets which need them (not necessarily > limited to truncate.c and dd.c). >
In libbb/xatonum.c there is the bkm_suffixes struct which seems to be used by head, tail and od. The struct contains the b, k and m suffixes. Is there a reason why this restricted set could not be extended? Best regards, Ari Sundholm [email protected] _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
