summaryrefslogtreecommitdiff
path: root/ln.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-11-06 06:07:27 +0000
committerEric Andersen <andersen@codepoet.org>1999-11-06 06:07:27 +0000
commit29d2e362dedf42d60ffebf6756144fb5449e753a (patch)
tree57ba26bdcf5dae8deb91a3d1a9b47bcc140689a0 /ln.c
parentbc3419069494fac078b316ce3a2f6a232c763c3e (diff)
downloadbusybox-w32-29d2e362dedf42d60ffebf6756144fb5449e753a.tar.gz
busybox-w32-29d2e362dedf42d60ffebf6756144fb5449e753a.tar.bz2
busybox-w32-29d2e362dedf42d60ffebf6756144fb5449e753a.zip
Fixed ln, df, and removed redundant stuff from mtab.
Diffstat (limited to 'ln.c')
-rw-r--r--ln.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/ln.c b/ln.c
index 1e30e2b29..62496fba0 100644
--- a/ln.c
+++ b/ln.c
@@ -27,23 +27,21 @@
27#include <errno.h> 27#include <errno.h>
28 28
29 29
30static const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n" 30static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n"
31"\n" 31"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n"
32"\tAdd a new name that refers to the same file as \"original-name\"\n" 32"\nOptions:\n"
33"\n" 33"\t-s\tmake symbolic links instead of hard links\n"
34"\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n" 34"\t-f\tremove existing destination files\n";
35"\t-f:\tRemove existing destination files.\n";
36 35
37 36
38static int symlinkFlag = FALSE; 37static int symlinkFlag = FALSE;
39static int removeoldFlag = FALSE; 38static int removeoldFlag = FALSE;
40static const char *destName;
41 39
42 40
43extern int ln_main(int argc, char **argv) 41extern int ln_main(int argc, char **argv)
44{ 42{
45 int status; 43 int status;
46 char newdestName[NAME_MAX]; 44 static char* linkName;
47 45
48 if (argc < 3) { 46 if (argc < 3) {
49 usage (ln_usage); 47 usage (ln_usage);
@@ -69,30 +67,27 @@ extern int ln_main(int argc, char **argv)
69 } 67 }
70 68
71 69
72 destName = argv[argc - 1]; 70 linkName = argv[argc - 1];
73 71
74 if ((argc > 3) && !(isDirectory(destName))) { 72 if ((argc > 3) && !(isDirectory(linkName))) {
75 fprintf(stderr, "%s: not a directory\n", destName); 73 fprintf(stderr, "%s: not a directory\n", linkName);
76 exit (FALSE); 74 exit (FALSE);
77 } 75 }
78 76
79 while (argc-- >= 2) { 77 while (argc-- >= 2) {
80 strcpy(newdestName, destName);
81 strcat(newdestName, (*argv)+(strlen(*(++argv))));
82
83 if (removeoldFlag==TRUE ) { 78 if (removeoldFlag==TRUE ) {
84 status = ( unlink(newdestName) && errno != ENOENT ); 79 status = ( unlink(linkName) && errno != ENOENT );
85 if ( status != 0 ) { 80 if ( status != 0 ) {
86 perror(newdestName); 81 perror(linkName);
87 exit( FALSE); 82 exit( FALSE);
88 } 83 }
89 } 84 }
90 if ( symlinkFlag==TRUE) 85 if ( symlinkFlag==TRUE)
91 status = symlink(*argv, newdestName); 86 status = symlink(*argv, linkName);
92 else 87 else
93 status = link(*argv, newdestName); 88 status = link(*argv, linkName);
94 if ( status != 0 ) { 89 if ( status != 0 ) {
95 perror(newdestName); 90 perror(linkName);
96 exit( FALSE); 91 exit( FALSE);
97 } 92 }
98 } 93 }