aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-03-01 21:36:20 -0600
committerRob Landley <rob@landley.net>2012-03-01 21:36:20 -0600
commit829503ea7f76c0ab52ba7c683f93878f56cab6a1 (patch)
treee169579d043aa180721b65a24434341f1a669687 /toys
parentf2e61cb1bb9bc02362833e4b6126ef3436236c9a (diff)
downloadtoybox-829503ea7f76c0ab52ba7c683f93878f56cab6a1.tar.gz
Add -n, which kernel build needs.
Diffstat (limited to 'toys')
-rw-r--r--toys/ln.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/toys/ln.c b/toys/ln.c
index 856db47b..6f55971a 100644
--- a/toys/ln.c
+++ b/toys/ln.c
@@ -6,7 +6,7 @@
*
* See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ln.html
-USE_LN(NEWTOY(ln, "<1fs", TOYFLAG_BIN))
+USE_LN(NEWTOY(ln, "<1nfs", TOYFLAG_BIN))
config LN
bool "ln"
@@ -14,17 +14,19 @@ config LN
help
usage: ln [-sf] [FROM...] TO
- Create a link between FROM and TO.
- With only one argument, create link in current directory.
+ Create a link between FROM and TO.
+ With only one argument, create link in current directory.
- -s Create a symbolic link
- -f Force the creation of the link, even if TO already exists
+ -s Create a symbolic link
+ -f Force the creation of the link, even if TO already exists
+ -n Symlink at destination treated as file
*/
#include "toys.h"
#define FLAG_s 1
-#define FLAG_f 2
+#define FLAG_f 2
+#define FLAG_n 4
void ln_main(void)
{
@@ -39,7 +41,9 @@ void ln_main(void)
}
// Is destination a directory?
- if (stat(dest, &buf) || !S_ISDIR(buf.st_mode)) {
+ if (((toys.optflags&FLAG_n) ? lstat : stat)(dest, &buf)
+ || !S_ISDIR(buf.st_mode))
+ {
if (toys.optc>1) error_exit("'%s' not a directory");
buf.st_mode = 0;
}
@@ -57,7 +61,6 @@ void ln_main(void)
* then we just move on */
if (toys.optflags & FLAG_f) unlink(new);
-
rc = (toys.optflags & FLAG_s) ? symlink(try, new) : link(try, new);
if (rc)
perror_exit("cannot create %s link from '%s' to '%s'",