[PATCH] Add coreutils/unlink.c
Isaac Dunham
ibid.ag at gmail.com
Sat Jun 21 21:01:10 UTC 2014
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
-------------- next part --------------
>From 135628b220c32741dc86ccef8f0dfb13eaaee206 Mon Sep 17 00:00:00 2001
From: Isaac Dunham <ibid.ag at gmail.com>
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 - 118 +118
.rodata 135671 135760 +89
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: 252/0) Total: 252 bytes
Not important but nice.
---
coreutils/unlink.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
create mode 100644 coreutils/unlink.c
diff --git a/coreutils/unlink.c b/coreutils/unlink.c
new file mode 100644
index 0000000..5a76ba9
--- /dev/null
+++ b/coreutils/unlink.c
@@ -0,0 +1,36 @@
+/* vi: set sw=4 ts=4: */
+/* unlink for busybox
+ *
+ * Copyright (C) 2014 Isaac Dunham <ibid.ag at gmail.com>
+ *
+ * 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_perror_msg_and_die("no file specified");
+ if (argc > 2)
+ bb_perror_msg_and_die("extra files");
+ if (unlink(argv[1]))
+ bb_perror_msg_and_die("can't delete '%s'", argv[0]);
+ else return 0;
+}
--
2.0.0
More information about the busybox
mailing list