[PATCH] Add coreutils/unlink.c

tito farmatito at tiscali.it
Sun Jun 22 06:11:25 UTC 2014


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.
> If you would rather shrink those, I don't object.
> 
> I wrote this because (a) it's POSIX and (b) I occasionally use unlink,
> and I saw a patch in the alpine aports tree converting unlink to rm.
> 
> HTH,
> Isaac Dunham
> 

Hi,
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;
}

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]);

Eventually instead of getopt32 you can use:

if (argc != 2)
	bb_show_usage();

Hope this helps.

Ciao,
Tito


More information about the busybox mailing list