[PATCH] truncate: new applet

Ari Sundholm ari at tuxera.com
Tue Mar 3 17:22:32 UTC 2015


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 <ari at tuxera.com>
> > ---
> >  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).

Best regards,
Ari Sundholm
ari at tuxera.com



More information about the busybox mailing list