[PATCH] [v2] Add coreutils/unlink.c

Denys Vlasenko vda.linux at googlemail.com
Sun Jun 22 18:44:48 UTC 2014


On Sunday 22 June 2014 16:45, Isaac Dunham wrote:
> Attaching a revised patch, based on Tito's suggestions.
> 
> On Sun, Jun 22, 2014 at 08:11:25AM +0200, tito wrote:
> > On Saturday 21 June 2014 23:01:10 Isaac Dunham wrote:
> > > Here's an implementation of the "unlink" command.
> > > Adds 252 bytes when enabled; a fair part is the error messages and text.
> > 
> > maybe it could be simplyfied, that way you get
> > the error messages for free and also support
> > -h to show usage text.
> > This is untested as I am in a hurry now.
> > 
> > int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
> > int unlink_main(int argc, char **argv)
> > {
> >      
> >       opt_complementary = "=1"; 	
> >       
> >       getopt32(argv, "");
> > 
> >       if (unlink(argv[1]))
> >                bb_perror_msg_and_die("can't delete '%s'", argv[1]);
> >       return 0;
> > }
> 
> Shrinks .rodata by 30 bytes

We have xunlink().

> 
> > 
> > also the line:
> > 
> >  bb_perror_msg_and_die("can't delete '%s'", argv[0]);
> > 
> > should be:
> > 
> >  bb_perror_msg_and_die("can't delete '%s'", argv[1]);
> Oops.
> 
> > Eventually instead of getopt32 you can use:
> > 
> > if (argc != 2)
> > 	bb_show_usage();
> 
> Thanks; this also shrinks unlink_main by 22 bytes for a 200-byte total.
> If I could do bb_show_trivial_usage() instead (just unlink_trivil_usage,
> no full usage or "Busybox ..."), that would have seemed more appropriate.
> But that doesn't exist, so...oh well.

Unfortunately, you were given bad advise. getopt32("") handles parameters such as
"--" and "-notsupportedoptions".

I'm changing the code to:

int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unlink_main(int argc UNUSED_PARAM, char **argv)
{
        opt_complementary = "=1"; /* must have exactly 1 param */
        getopt32(argv, "");
        argv += optind;
        xunlink(argv[0]);
        return 0;
}

Applied, thanks!


More information about the busybox mailing list