[PATCH] exch: new applet
Sertonix via busybox <[email protected]>
| Newsgroups | gmane.linux.busybox |
|---|---|
| Message-ID | <[email protected]> |
Has the unique ability to atomically replace a directory
function old new delta
exch_main - 83 +83
.rodata 102803 102837 +34
packed_usage 35215 35242 +27
applet_main 3256 3264 +8
applet_names 2814 2819 +5
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/0 up/down: 157/0) Total: 157 bytes
---
util-linux/exch.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
create mode 100644 util-linux/exch.c
diff --git a/util-linux/exch.c b/util-linux/exch.c
new file mode 100644
index 000000000..47567217b
--- /dev/null
+++ b/util-linux/exch.c
@@ -0,0 +1,35 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * exch for busybox
+ *
+ * Licensed under GPLv2, see LICENSE in this source tree
+ */
+//config:config EXCH
+//config: bool "exch (4.4 kb)"
+//config: default n
+//config: help
+//config: exch is used to atomically exchange 2 files or directories
+//config:
+//config: requires renameat2()
+
+//applet:IF_EXCH(APPLET_NOFORK(exch, exch, BB_DIR_USR_BIN, BB_SUID_DROP, exch))
+
+//kbuild:lib-$(CONFIG_EXCH) += exch.o
+
+//usage:#define exch_trivial_usage
+//usage: "PATH PATH"
+//usage:#define exch_full_usage "\n\n"
+//usage: "Atomically exchange 2 paths"
+
+#define _GNU_SOURCE 1 /* for renameat2 */
+#include "libbb.h"
+
+int exch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int exch_main(int argc UNUSED_PARAM, char **argv)
+{
+ getopt32(argv, "^" "" "\0" "=2");
+ argv += optind;
+ if (renameat2(AT_FDCWD, argv[0], AT_FDCWD, argv[1], RENAME_EXCHANGE))
+ bb_perror_msg_and_die("can't exchange '%s' and '%s'", argv[0], argv[1]);
+ return EXIT_SUCCESS;
+}
--
2.53.0