2017-01-26 04:57:53 +05:30
|
|
|
/*
|
|
|
|
* link implementation for busybox
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
|
|
|
|
*
|
|
|
|
* Licensed under GPLv2, see file LICENSE in this source tree.
|
|
|
|
*/
|
|
|
|
//config:config LINK
|
2017-07-19 01:31:24 +05:30
|
|
|
//config: bool "link (3.1 kb)"
|
2017-01-26 04:57:53 +05:30
|
|
|
//config: default y
|
|
|
|
//config: help
|
2017-07-21 13:20:55 +05:30
|
|
|
//config: link creates hard links between files.
|
2017-01-26 04:57:53 +05:30
|
|
|
|
|
|
|
//applet:IF_LINK(APPLET_NOFORK(link, link, BB_DIR_BIN, BB_SUID_DROP, link))
|
|
|
|
|
|
|
|
//kbuild:lib-$(CONFIG_LINK) += link.o
|
|
|
|
|
|
|
|
//usage:#define link_trivial_usage
|
|
|
|
//usage: "FILE LINK"
|
|
|
|
//usage:#define link_full_usage "\n\n"
|
|
|
|
//usage: "Create hard LINK to FILE"
|
|
|
|
|
|
|
|
#include "libbb.h"
|
|
|
|
|
|
|
|
/* This is a NOFORK applet. Be very careful! */
|
|
|
|
|
|
|
|
int link_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|
|
|
int link_main(int argc UNUSED_PARAM, char **argv)
|
|
|
|
{
|
2017-08-09 01:25:02 +05:30
|
|
|
getopt32(argv, "^" "" "\0" "=2");
|
2017-01-26 04:57:53 +05:30
|
|
|
argv += optind;
|
|
|
|
if (link(argv[0], argv[1]) != 0) {
|
|
|
|
/* shared message */
|
|
|
|
bb_perror_msg_and_die("can't create %slink "
|
2017-07-24 20:50:13 +05:30
|
|
|
"'%s' to '%s'", "hard",
|
2017-01-26 04:57:53 +05:30
|
|
|
argv[1], argv[0]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|