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
This commit is contained in:
parent
a03d86cf54
commit
0b4551faf5
10
basename.c
10
basename.c
@ -43,14 +43,7 @@ extern int basename_main(int argc, char **argv)
|
|||||||
|
|
||||||
argv++;
|
argv++;
|
||||||
|
|
||||||
s1=*argv+strlen(*argv)-1;
|
s = get_last_path_component(*argv);
|
||||||
while (s1 && *s1 == '/') {
|
|
||||||
*s1 = '\0';
|
|
||||||
s1--;
|
|
||||||
}
|
|
||||||
s = strrchr(*argv, '/');
|
|
||||||
if (s==NULL) s=*argv;
|
|
||||||
else s++;
|
|
||||||
|
|
||||||
if (argc>2) {
|
if (argc>2) {
|
||||||
argv++;
|
argv++;
|
||||||
@ -62,4 +55,3 @@ extern int basename_main(int argc, char **argv)
|
|||||||
printf("%s\n", s);
|
printf("%s\n", s);
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,14 +43,7 @@ extern int basename_main(int argc, char **argv)
|
|||||||
|
|
||||||
argv++;
|
argv++;
|
||||||
|
|
||||||
s1=*argv+strlen(*argv)-1;
|
s = get_last_path_component(*argv);
|
||||||
while (s1 && *s1 == '/') {
|
|
||||||
*s1 = '\0';
|
|
||||||
s1--;
|
|
||||||
}
|
|
||||||
s = strrchr(*argv, '/');
|
|
||||||
if (s==NULL) s=*argv;
|
|
||||||
else s++;
|
|
||||||
|
|
||||||
if (argc>2) {
|
if (argc>2) {
|
||||||
argv++;
|
argv++;
|
||||||
@ -62,4 +55,3 @@ extern int basename_main(int argc, char **argv)
|
|||||||
printf("%s\n", s);
|
printf("%s\n", s);
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ static int followLinks = TRUE;
|
|||||||
|
|
||||||
extern int ln_main(int argc, char **argv)
|
extern int ln_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *linkName;
|
char *linkName, *dirName;
|
||||||
int linkIntoDirFlag;
|
int linkIntoDirFlag;
|
||||||
int stopIt = FALSE;
|
int stopIt = FALSE;
|
||||||
|
|
||||||
@ -104,6 +104,9 @@ extern int ln_main(int argc, char **argv)
|
|||||||
exit FALSE;
|
exit FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (linkIntoDirFlag == TRUE)
|
||||||
|
dirName = linkName;
|
||||||
|
|
||||||
while (argc-- >= 2) {
|
while (argc-- >= 2) {
|
||||||
#if 0
|
#if 0
|
||||||
char srcName[BUFSIZ + 1];
|
char srcName[BUFSIZ + 1];
|
||||||
@ -126,6 +129,14 @@ extern int ln_main(int argc, char **argv)
|
|||||||
srcName[nChars] = '\0';
|
srcName[nChars] = '\0';
|
||||||
}
|
}
|
||||||
#endif
|
#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) {
|
if (removeoldFlag == TRUE) {
|
||||||
status = (unlink(linkName) && errno != ENOENT);
|
status = (unlink(linkName) && errno != ENOENT);
|
||||||
@ -143,6 +154,11 @@ extern int ln_main(int argc, char **argv)
|
|||||||
perror(linkName);
|
perror(linkName);
|
||||||
exit FALSE;
|
exit FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (linkIntoDirFlag)
|
||||||
|
free(linkName);
|
||||||
|
|
||||||
|
argv++;
|
||||||
}
|
}
|
||||||
return( TRUE);
|
return( TRUE);
|
||||||
}
|
}
|
||||||
|
@ -259,6 +259,7 @@ extern void *xmalloc (size_t size);
|
|||||||
extern int find_real_root_device_name(char* name);
|
extern int find_real_root_device_name(char* name);
|
||||||
extern char *get_line_from_file(FILE *file);
|
extern char *get_line_from_file(FILE *file);
|
||||||
extern char process_escape_sequence(char **ptr);
|
extern char process_escape_sequence(char **ptr);
|
||||||
|
extern char *get_last_path_component(char *path);
|
||||||
|
|
||||||
/* These parse entries in /etc/passwd and /etc/group. This is desirable
|
/* These parse entries in /etc/passwd and /etc/group. This is desirable
|
||||||
* for BusyBox since we want to avoid using the glibc NSS stuff, which
|
* for BusyBox since we want to avoid using the glibc NSS stuff, which
|
||||||
|
18
ln.c
18
ln.c
@ -52,7 +52,7 @@ static int followLinks = TRUE;
|
|||||||
|
|
||||||
extern int ln_main(int argc, char **argv)
|
extern int ln_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *linkName;
|
char *linkName, *dirName;
|
||||||
int linkIntoDirFlag;
|
int linkIntoDirFlag;
|
||||||
int stopIt = FALSE;
|
int stopIt = FALSE;
|
||||||
|
|
||||||
@ -104,6 +104,9 @@ extern int ln_main(int argc, char **argv)
|
|||||||
exit FALSE;
|
exit FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (linkIntoDirFlag == TRUE)
|
||||||
|
dirName = linkName;
|
||||||
|
|
||||||
while (argc-- >= 2) {
|
while (argc-- >= 2) {
|
||||||
#if 0
|
#if 0
|
||||||
char srcName[BUFSIZ + 1];
|
char srcName[BUFSIZ + 1];
|
||||||
@ -126,6 +129,14 @@ extern int ln_main(int argc, char **argv)
|
|||||||
srcName[nChars] = '\0';
|
srcName[nChars] = '\0';
|
||||||
}
|
}
|
||||||
#endif
|
#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) {
|
if (removeoldFlag == TRUE) {
|
||||||
status = (unlink(linkName) && errno != ENOENT);
|
status = (unlink(linkName) && errno != ENOENT);
|
||||||
@ -143,6 +154,11 @@ extern int ln_main(int argc, char **argv)
|
|||||||
perror(linkName);
|
perror(linkName);
|
||||||
exit FALSE;
|
exit FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (linkIntoDirFlag)
|
||||||
|
free(linkName);
|
||||||
|
|
||||||
|
argv++;
|
||||||
}
|
}
|
||||||
return( TRUE);
|
return( TRUE);
|
||||||
}
|
}
|
||||||
|
17
utility.c
17
utility.c
@ -1675,6 +1675,23 @@ char process_escape_sequence(char **ptr)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined BB_BASENAME || defined BB_LN
|
||||||
|
char *get_last_path_component(char *path)
|
||||||
|
{
|
||||||
|
char *s=path+strlen(path)-1;
|
||||||
|
|
||||||
|
/* strip trailing slashes */
|
||||||
|
while (s && *s == '/') {
|
||||||
|
*s-- = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* find last component */
|
||||||
|
s = strrchr(path, '/');
|
||||||
|
if (s==NULL) return path;
|
||||||
|
else return s+1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* END CODE */
|
/* END CODE */
|
||||||
/*
|
/*
|
||||||
Local Variables:
|
Local Variables:
|
||||||
|
Loading…
Reference in New Issue
Block a user