aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon B <sburnet@hotmail.com>2012-05-06 13:18:35 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2012-05-06 13:18:35 +0200
commit44642d1ec15edf4a4448085849105ec93fa01ef2 (patch)
treefdc992e9609cef515c28e631d4424063034b2812
parent556ac3633ce3e7bd51c93b78827ae3874d856257 (diff)
downloadbusybox-w32-44642d1ec15edf4a4448085849105ec93fa01ef2.tar.gz
busybox-w32-44642d1ec15edf4a4448085849105ec93fa01ef2.tar.bz2
busybox-w32-44642d1ec15edf4a4448085849105ec93fa01ef2.zip
ln: support -T and -v
function old new delta ln_main 445 524 +79 packed_usage 29182 29179 -3 Signed-off-by: Simon B <sburnet@hotmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/ln.c28
-rw-r--r--libbb/remove_file.c2
2 files changed, 23 insertions, 7 deletions
diff --git a/coreutils/ln.c b/coreutils/ln.c
index 0eb3e6579..3b822e8c7 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -20,6 +20,8 @@
20//usage: "\n -n Don't dereference symlinks - treat like normal file" 20//usage: "\n -n Don't dereference symlinks - treat like normal file"
21//usage: "\n -b Make a backup of the target (if exists) before link operation" 21//usage: "\n -b Make a backup of the target (if exists) before link operation"
22//usage: "\n -S suf Use suffix instead of ~ when making backup files" 22//usage: "\n -S suf Use suffix instead of ~ when making backup files"
23//usage: "\n -T 2nd arg must be a DIR"
24//usage: "\n -v Verbose"
23//usage: 25//usage:
24//usage:#define ln_example_usage 26//usage:#define ln_example_usage
25//usage: "$ ln -s BusyBox /tmp/ls\n" 27//usage: "$ ln -s BusyBox /tmp/ls\n"
@@ -31,11 +33,13 @@
31/* This is a NOEXEC applet. Be very careful! */ 33/* This is a NOEXEC applet. Be very careful! */
32 34
33 35
34#define LN_SYMLINK 1 36#define LN_SYMLINK (1 << 0)
35#define LN_FORCE 2 37#define LN_FORCE (1 << 1)
36#define LN_NODEREFERENCE 4 38#define LN_NODEREFERENCE (1 << 2)
37#define LN_BACKUP 8 39#define LN_BACKUP (1 << 3)
38#define LN_SUFFIX 16 40#define LN_SUFFIX (1 << 4)
41#define LN_VERBOSE (1 << 5)
42#define LN_LINKFILE (1 << 6)
39 43
40int ln_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 44int ln_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
41int ln_main(int argc, char **argv) 45int ln_main(int argc, char **argv)
@@ -50,10 +54,15 @@ int ln_main(int argc, char **argv)
50 int (*link_func)(const char *, const char *); 54 int (*link_func)(const char *, const char *);
51 55
52 opt_complementary = "-1"; /* min one arg */ 56 opt_complementary = "-1"; /* min one arg */
53 opts = getopt32(argv, "sfnbS:", &suffix); 57 opts = getopt32(argv, "sfnbS:vT", &suffix);
54 58
55 last = argv[argc - 1]; 59 last = argv[argc - 1];
56 argv += optind; 60 argv += optind;
61 argc -= optind;
62
63 if ((opts & LN_LINKFILE) && argc > 2) {
64 bb_error_msg_and_die("-T accepts 2 args max");
65 }
57 66
58 if (!argv[1]) { 67 if (!argv[1]) {
59 /* "ln PATH/TO/FILE" -> "ln PATH/TO/FILE FILE" */ 68 /* "ln PATH/TO/FILE" -> "ln PATH/TO/FILE FILE" */
@@ -72,6 +81,9 @@ int ln_main(int argc, char **argv)
72 (opts & LN_NODEREFERENCE) ^ LN_NODEREFERENCE 81 (opts & LN_NODEREFERENCE) ^ LN_NODEREFERENCE
73 ) 82 )
74 ) { 83 ) {
84 if (opts & LN_LINKFILE) {
85 bb_error_msg_and_die("'%s' is a directory", src);
86 }
75 src_name = xstrdup(*argv); 87 src_name = xstrdup(*argv);
76 src = concat_path_file(src, bb_get_last_path_component_strip(src_name)); 88 src = concat_path_file(src, bb_get_last_path_component_strip(src_name));
77 free(src_name); 89 free(src_name);
@@ -112,6 +124,10 @@ int ln_main(int argc, char **argv)
112 link_func = symlink; 124 link_func = symlink;
113 } 125 }
114 126
127 if (opts & LN_VERBOSE) {
128 printf("'%s' -> '%s'\n", src, *argv);
129 }
130
115 if (link_func(*argv, src) != 0) { 131 if (link_func(*argv, src) != 0) {
116 bb_simple_perror_msg(src); 132 bb_simple_perror_msg(src);
117 status = EXIT_FAILURE; 133 status = EXIT_FAILURE;
diff --git a/libbb/remove_file.c b/libbb/remove_file.c
index c6531a0b9..5b75f7f30 100644
--- a/libbb/remove_file.c
+++ b/libbb/remove_file.c
@@ -33,7 +33,7 @@ int FAST_FUNC remove_file(const char *path, int flags)
33 int status = 0; 33 int status = 0;
34 34
35 if (!(flags & FILEUTILS_RECUR)) { 35 if (!(flags & FILEUTILS_RECUR)) {
36 bb_error_msg("%s: is a directory", path); 36 bb_error_msg("'%s' is a directory", path);
37 return -1; 37 return -1;
38 } 38 }
39 39