[PATCH 2/2 v5] truncate: new applet

Ari Sundholm ari at tuxera.com
Fri Mar 6 12:29:08 UTC 2015


On Thu, 2015-03-05 at 23:11 +0100, Bernhard Reutner-Fischer wrote:
> On March 5, 2015 8:57:05 PM GMT+01:00, Ari Sundholm <ari at tuxera.com> wrote:
>>+      opt_complementary = "s";
>>+      opts = getopt32(argv, "cs:", &size_str);
>>+
> >+	if (!*argv)
> >+		bb_error_msg_and_die("no files specified!");
> 
> opt_complementary = "-1"; at least one non-option arg

Thanks, changed to "s:-1", as the presence of the -s option has to be
checked as well.

> >+
> >+	if (opts & OPT_NOCREATE)
> >+		flags = O_RDWR;
> 
> Wasteful.

Do you have a suggestion how to make this less wasteful? The presence of
the -c option has to be checked and its effect on the open() flags put
in effect somehow. Or do you think the entire -c option is unneeded?

> >+	while (*argv) {
> >+		fd = xopen(*argv, flags);
> >+		if (ftruncate(fd, size) == -1)
> >+			bb_perror_msg_and_die("ftruncate failed");
> 
> " failed" is redundant.

Indeed. Thanks.

> I would only accept this as a shell script, but that's Denys call.

This applet was borne out of a real need and, for us, was one of the
important things that was missing but needed of busybox. Having to
maintain separate wrapper scripts gets old pretty fast when the
alternative would be to be able to just deploy a busybox with all tools
needed. Of course, we have no desire to bloat busybox unnecessarily.
This applet was judged generally useful and thus submitted for mainline
inclusion.

BTW, I took a look at my dd wrapper script and it is considerably bigger
than the applet and doesn't do as much as the applet does. And the
applet is of course entirely optional even if accepted.

Best regards,
Ari Sundholm
ari at tuxera.com



More information about the busybox mailing list