aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--basename.c10
-rw-r--r--coreutils/basename.c10
-rw-r--r--coreutils/ln.c18
-rw-r--r--internal.h1
-rw-r--r--ln.c18
-rw-r--r--utility.c17
6 files changed, 54 insertions, 20 deletions
diff --git a/basename.c b/basename.c
index ac371d274..fa15aa979 100644
--- a/basename.c
+++ b/basename.c
@@ -43,14 +43,7 @@ extern int basename_main(int argc, char **argv)
43 43
44 argv++; 44 argv++;
45 45
46 s1=*argv+strlen(*argv)-1; 46 s = get_last_path_component(*argv);
47 while (s1 && *s1 == '/') {
48 *s1 = '\0';
49 s1--;
50 }
51 s = strrchr(*argv, '/');
52 if (s==NULL) s=*argv;
53 else s++;
54 47
55 if (argc>2) { 48 if (argc>2) {
56 argv++; 49 argv++;
@@ -62,4 +55,3 @@ extern int basename_main(int argc, char **argv)
62 printf("%s\n", s); 55 printf("%s\n", s);
63 return(TRUE); 56 return(TRUE);
64} 57}
65
diff --git a/coreutils/basename.c b/coreutils/basename.c
index ac371d274..fa15aa979 100644
--- a/coreutils/basename.c
+++ b/coreutils/basename.c
@@ -43,14 +43,7 @@ extern int basename_main(int argc, char **argv)
43 43
44 argv++; 44 argv++;
45 45
46 s1=*argv+strlen(*argv)-1; 46 s = get_last_path_component(*argv);
47 while (s1 && *s1 == '/') {
48 *s1 = '\0';
49 s1--;
50 }
51 s = strrchr(*argv, '/');
52 if (s==NULL) s=*argv;
53 else s++;
54 47
55 if (argc>2) { 48 if (argc>2) {
56 argv++; 49 argv++;
@@ -62,4 +55,3 @@ extern int basename_main(int argc, char **argv)
62 printf("%s\n", s); 55 printf("%s\n", s);
63 return(TRUE); 56 return(TRUE);
64} 57}
65
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}
diff --git a/internal.h b/internal.h
index 362df3270..a4772b820 100644
--- a/internal.h
+++ b/internal.h
@@ -259,6 +259,7 @@ extern void *xmalloc (size_t size);
259extern int find_real_root_device_name(char* name); 259extern int find_real_root_device_name(char* name);
260extern char *get_line_from_file(FILE *file); 260extern char *get_line_from_file(FILE *file);
261extern char process_escape_sequence(char **ptr); 261extern char process_escape_sequence(char **ptr);
262extern char *get_last_path_component(char *path);
262 263
263/* These parse entries in /etc/passwd and /etc/group. This is desirable 264/* These parse entries in /etc/passwd and /etc/group. This is desirable
264 * for BusyBox since we want to avoid using the glibc NSS stuff, which 265 * for BusyBox since we want to avoid using the glibc NSS stuff, which
diff --git a/ln.c b/ln.c
index 57e412dc8..beaa58fac 100644
--- a/ln.c
+++ b/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}
diff --git a/utility.c b/utility.c
index a15ae68da..a313078cf 100644
--- a/utility.c
+++ b/utility.c
@@ -1675,6 +1675,23 @@ char process_escape_sequence(char **ptr)
1675} 1675}
1676#endif 1676#endif
1677 1677
1678#if defined BB_BASENAME || defined BB_LN
1679char *get_last_path_component(char *path)
1680{
1681 char *s=path+strlen(path)-1;
1682
1683 /* strip trailing slashes */
1684 while (s && *s == '/') {
1685 *s-- = '\0';
1686 }
1687
1688 /* find last component */
1689 s = strrchr(path, '/');
1690 if (s==NULL) return path;
1691 else return s+1;
1692}
1693#endif
1694
1678/* END CODE */ 1695/* END CODE */
1679/* 1696/*
1680Local Variables: 1697Local Variables: