summaryrefslogtreecommitdiff
path: root/coreutils/ln.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-07-10 16:44:03 +0000
committerEric Andersen <andersen@codepoet.org>2000-07-10 16:44:03 +0000
commit0b4551faf520e44a9a0bf2ac72b3dcd6a145a0a1 (patch)
tree4694959864edc8f08b950f9cc2547dfe87422819 /coreutils/ln.c
parenta03d86cf5496a24ccf81bfbf8fdbb10b1ad13a0a (diff)
downloadbusybox-w32-0b4551faf520e44a9a0bf2ac72b3dcd6a145a0a1.tar.gz
busybox-w32-0b4551faf520e44a9a0bf2ac72b3dcd6a145a0a1.tar.bz2
busybox-w32-0b4551faf520e44a9a0bf2ac72b3dcd6a145a0a1.zip
From Matt Kraai <kraai@alumni.carnegiemellon.edu>:
Howdy, Bug #1006 reports that ln -s /tmp/foo . does not work correctly. In fact, it appears that any instantiation of ln -s FILE... DIRECTORY does not work. The following patch adds support for this form, which then fixes the particular instance noted in the bug report. In the process, I needed the basename function. This appears in the string.h provided by glibc, but not uC-libc. So I wrote my own to go in utility.c, called get_last_path_component. I also modified the basename utility to use this function. At some point it might be desirous to use the basename from the library if it exists, and otherwise compile our own. But I don't know how to do this. Matt
Diffstat (limited to 'coreutils/ln.c')
-rw-r--r--coreutils/ln.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/coreutils/ln.c b/coreutils/ln.c
index 57e412dc8..beaa58fac 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -52,7 +52,7 @@ static int followLinks = TRUE;
52 52
53extern int ln_main(int argc, char **argv) 53extern int ln_main(int argc, char **argv)
54{ 54{
55 char *linkName; 55 char *linkName, *dirName;
56 int linkIntoDirFlag; 56 int linkIntoDirFlag;
57 int stopIt = FALSE; 57 int stopIt = FALSE;
58 58
@@ -104,6 +104,9 @@ extern int ln_main(int argc, char **argv)
104 exit FALSE; 104 exit FALSE;
105 } 105 }
106 106
107 if (linkIntoDirFlag == TRUE)
108 dirName = linkName;
109
107 while (argc-- >= 2) { 110 while (argc-- >= 2) {
108#if 0 111#if 0
109 char srcName[BUFSIZ + 1]; 112 char srcName[BUFSIZ + 1];
@@ -126,6 +129,14 @@ extern int ln_main(int argc, char **argv)
126 srcName[nChars] = '\0'; 129 srcName[nChars] = '\0';
127 } 130 }
128#endif 131#endif
132 if (linkIntoDirFlag == TRUE) {
133 char *baseName = get_last_path_component(*argv);
134 linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
135 strcpy(linkName, dirName);
136 if(dirName[strlen(dirName)-1] != '/')
137 strcat(linkName, "/");
138 strcat(linkName,baseName);
139 }
129 140
130 if (removeoldFlag == TRUE) { 141 if (removeoldFlag == TRUE) {
131 status = (unlink(linkName) && errno != ENOENT); 142 status = (unlink(linkName) && errno != ENOENT);
@@ -143,6 +154,11 @@ extern int ln_main(int argc, char **argv)
143 perror(linkName); 154 perror(linkName);
144 exit FALSE; 155 exit FALSE;
145 } 156 }
157
158 if (linkIntoDirFlag)
159 free(linkName);
160
161 argv++;
146 } 162 }
147 return( TRUE); 163 return( TRUE);
148} 164}