diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-07-10 20:44:03 +0400 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-07-10 20:44:03 +0400 |
commit | 0b4551faf520e44a9a0bf2ac72b3dcd6a145a0a1 (patch) | |
tree | 4694959864edc8f08b950f9cc2547dfe87422819 /coreutils/ln.c | |
parent | a03d86cf5496a24ccf81bfbf8fdbb10b1ad13a0a (diff) |
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.c | 18 |
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; extern int ln_main(int argc, char **argv) { - char *linkName; + char *linkName, *dirName; int linkIntoDirFlag; int stopIt = FALSE; @@ -104,6 +104,9 @@ extern int ln_main(int argc, char **argv) exit FALSE; } + if (linkIntoDirFlag == TRUE) + dirName = linkName; + while (argc-- >= 2) { #if 0 char srcName[BUFSIZ + 1]; @@ -126,6 +129,14 @@ extern int ln_main(int argc, char **argv) srcName[nChars] = '\0'; } #endif + if (linkIntoDirFlag == TRUE) { + char *baseName = get_last_path_component(*argv); + linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2); + strcpy(linkName, dirName); + if(dirName[strlen(dirName)-1] != '/') + strcat(linkName, "/"); + strcat(linkName,baseName); + } if (removeoldFlag == TRUE) { status = (unlink(linkName) && errno != ENOENT); @@ -143,6 +154,11 @@ extern int ln_main(int argc, char **argv) perror(linkName); exit FALSE; } + + if (linkIntoDirFlag) + free(linkName); + + argv++; } return( TRUE); } |