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

> 
> 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.

--help comes for free.


Thanks,
Isaac Dunham
>From ca923ff6ae0f96beb6f1ad1480e7f0eed09fe8f9 Mon Sep 17 00:00:00 2001
From: Isaac Dunham <[email protected]>
Date: Sat, 21 Jun 2014 20:47:05 +0000
Subject: [PATCH] Add POSIX unlink command.

Change in size when enabled:
function                                             old     new   delta
unlink_main                                            -      96     +96
.rodata                                           135671  135730     +59
packed_usage                                       29477   29509     +32
applet_names                                        2436    2443      +7
applet_main                                         1420    1424      +4
applet_nameofs                                       710     712      +2
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 5/0 up/down: 200/0)             Total: 200 bytes

Not important but nice.
---
 coreutils/unlink.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 coreutils/unlink.c

diff --git a/coreutils/unlink.c b/coreutils/unlink.c
new file mode 100644
index 0000000..9069a50
--- /dev/null
+++ b/coreutils/unlink.c
@@ -0,0 +1,34 @@
+/* vi: set sw=4 ts=4: */
+/* unlink for busybox
+ *
+ * Copyright (C) 2014 Isaac Dunham <[email protected]>
+ *
+ * Licensed under GPLv2, see LICENSE in this source tree
+ */
+
+//kbuild:lib-$(CONFIG_UNLINK)  += unlink.o
+
+//config:config UNLINK
+//config:      bool "unlink"
+//config:      default n
+//config:      help
+//config:        unlink deletes a file by calling unlink()
+
+//applet:IF_UNLINK( APPLET( unlink, BB_DIR_USR_BIN, BB_SUID_DROP))
+
+//usage:#define unlink_trivial_usage 
+//usage:       "FILE"
+//usage:#define unlink_full_usage "\n\n"
+//usage:       "delete FILE by calling unlink()"
+
+#include "libbb.h"
+
+int unlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int unlink_main(int argc, char **argv)
+{
+       if (argc != 2)
+               bb_show_usage();
+       if (unlink(argv[1]))
+               bb_perror_msg_and_die("can't delete '%s'", argv[1]);
+       return 0;
+}
-- 
2.0.0

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to