argv++;
- s1=*argv+strlen(*argv)-1;
- while (s1 && *s1 == '/') {
- *s1 = '\0';
- s1--;
- }
- s = strrchr(*argv, '/');
- if (s==NULL) s=*argv;
- else s++;
+ s = get_last_path_component(*argv);
if (argc>2) {
argv++;
printf("%s\n", s);
return(TRUE);
}
-
argv++;
- s1=*argv+strlen(*argv)-1;
- while (s1 && *s1 == '/') {
- *s1 = '\0';
- s1--;
- }
- s = strrchr(*argv, '/');
- if (s==NULL) s=*argv;
- else s++;
+ s = get_last_path_component(*argv);
if (argc>2) {
argv++;
printf("%s\n", s);
return(TRUE);
}
-
extern int ln_main(int argc, char **argv)
{
- char *linkName;
+ char *linkName, *dirName;
int linkIntoDirFlag;
int stopIt = FALSE;
exit FALSE;
}
+ if (linkIntoDirFlag == TRUE)
+ dirName = linkName;
+
while (argc-- >= 2) {
#if 0
char srcName[BUFSIZ + 1];
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);
perror(linkName);
exit FALSE;
}
+
+ if (linkIntoDirFlag)
+ free(linkName);
+
+ argv++;
}
return( TRUE);
}
extern int find_real_root_device_name(char* name);
extern char *get_line_from_file(FILE *file);
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
* for BusyBox since we want to avoid using the glibc NSS stuff, which
extern int ln_main(int argc, char **argv)
{
- char *linkName;
+ char *linkName, *dirName;
int linkIntoDirFlag;
int stopIt = FALSE;
exit FALSE;
}
+ if (linkIntoDirFlag == TRUE)
+ dirName = linkName;
+
while (argc-- >= 2) {
#if 0
char srcName[BUFSIZ + 1];
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);
perror(linkName);
exit FALSE;
}
+
+ if (linkIntoDirFlag)
+ free(linkName);
+
+ argv++;
}
return( TRUE);
}
}
#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 */
/*
Local Variables: