diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-10-05 16:24:54 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-10-05 16:24:54 +0000 |
commit | cc8ed39b240180b58810784f844e253263594ac3 (patch) | |
tree | 15feebbb4be9a9168209609f48f0b100f9364420 /ln.c | |
download | busybox-w32-cc8ed39b240180b58810784f844e253263594ac3.tar.gz busybox-w32-cc8ed39b240180b58810784f844e253263594ac3.tar.bz2 busybox-w32-cc8ed39b240180b58810784f844e253263594ac3.zip |
Initial revision0_29alpha2
Diffstat (limited to 'ln.c')
-rw-r--r-- | ln.c | 52 |
1 files changed, 52 insertions, 0 deletions
@@ -0,0 +1,52 @@ | |||
1 | #include "internal.h" | ||
2 | #include <stdio.h> | ||
3 | #include <sys/stat.h> | ||
4 | #include <sys/param.h> | ||
5 | #include <errno.h> | ||
6 | |||
7 | const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n" | ||
8 | "\n" | ||
9 | "\tAdd a new name that refers to the same file as \"original-name\"\n" | ||
10 | "\n" | ||
11 | "\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n" | ||
12 | "\t-f:\tRemove existing destination files.\n"; | ||
13 | |||
14 | int | ||
15 | ln_fn(const struct FileInfo * i) | ||
16 | { | ||
17 | int status = 0; | ||
18 | char d[PATH_MAX]; | ||
19 | const char * destination = i->destination; | ||
20 | |||
21 | if ( !i->makeSymbolicLink && (i->stat.st_mode & S_IFMT) == S_IFDIR ) { | ||
22 | fprintf(stderr, "Please use \"ln -s\" to link directories.\n"); | ||
23 | return 1; | ||
24 | } | ||
25 | |||
26 | /* | ||
27 | * If the destination is a directory, create a file within it. | ||
28 | */ | ||
29 | if ( is_a_directory(i->destination) ) { | ||
30 | destination = join_paths( | ||
31 | d | ||
32 | ,i->destination | ||
33 | ,&i->source[i->directoryLength]); | ||
34 | } | ||
35 | |||
36 | if ( i->force ) | ||
37 | status = ( unlink(destination) && errno != ENOENT ); | ||
38 | |||
39 | if ( status == 0 ) { | ||
40 | if ( i->makeSymbolicLink ) | ||
41 | status = symlink(i->source, destination); | ||
42 | else | ||
43 | status = link(i->source, destination); | ||
44 | } | ||
45 | |||
46 | if ( status != 0 ) { | ||
47 | name_and_error(destination); | ||
48 | return 1; | ||
49 | } | ||
50 | else | ||
51 | return 0; | ||
52 | } | ||