From 1f3e8dc36947bdcc2d008fba3cdc29e2c79f9c27 Mon Sep 17 00:00:00 2001 From: andersen Date: Tue, 5 Oct 1999 16:24:54 +0000 Subject: Initial revision git-svn-id: svn://busybox.net/trunk/busybox@5 69ca8d6d-28ef-0310-b511-8ec308f3f277 --- ln.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 ln.c (limited to 'ln.c') diff --git a/ln.c b/ln.c new file mode 100644 index 000000000..3e87b579e --- /dev/null +++ b/ln.c @@ -0,0 +1,52 @@ +#include "internal.h" +#include +#include +#include +#include + +const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n" +"\n" +"\tAdd a new name that refers to the same file as \"original-name\"\n" +"\n" +"\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n" +"\t-f:\tRemove existing destination files.\n"; + +int +ln_fn(const struct FileInfo * i) +{ + int status = 0; + char d[PATH_MAX]; + const char * destination = i->destination; + + if ( !i->makeSymbolicLink && (i->stat.st_mode & S_IFMT) == S_IFDIR ) { + fprintf(stderr, "Please use \"ln -s\" to link directories.\n"); + return 1; + } + + /* + * If the destination is a directory, create a file within it. + */ + if ( is_a_directory(i->destination) ) { + destination = join_paths( + d + ,i->destination + ,&i->source[i->directoryLength]); + } + + if ( i->force ) + status = ( unlink(destination) && errno != ENOENT ); + + if ( status == 0 ) { + if ( i->makeSymbolicLink ) + status = symlink(i->source, destination); + else + status = link(i->source, destination); + } + + if ( status != 0 ) { + name_and_error(destination); + return 1; + } + else + return 0; +} -- cgit v1.2.3-55-g6feb