Another patch from Matt Kraai <kraai@alumni.carnegiemellon.edu>:
> > The following patch allows ln -n to function like GNU. It also fixes a > typo with my previous patch to add support for ln FILE DIRECTORY. And > it removes some code that checks the maximum length of the filenames. I > can't figure out why that code is necessary. Anyone know? > > Matt
This commit is contained in:
parent
61dc057183
commit
195fa15caf
@ -92,13 +92,7 @@ extern int ln_main(int argc, char **argv)
|
|||||||
|
|
||||||
linkName = argv[argc - 1];
|
linkName = argv[argc - 1];
|
||||||
|
|
||||||
if (strlen(linkName) > BUFSIZ) {
|
linkIntoDirFlag = isDirectory(linkName, followLinks, NULL);
|
||||||
fprintf(stderr, name_too_long, "ln");
|
|
||||||
exit FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
linkIntoDirFlag = isDirectory(linkName, TRUE, NULL);
|
|
||||||
|
|
||||||
if ((argc >= 3) && linkIntoDirFlag == FALSE) {
|
if ((argc >= 3) && linkIntoDirFlag == FALSE) {
|
||||||
fprintf(stderr, not_a_directory, "ln", linkName);
|
fprintf(stderr, not_a_directory, "ln", linkName);
|
||||||
exit FALSE;
|
exit FALSE;
|
||||||
@ -108,27 +102,8 @@ extern int ln_main(int argc, char **argv)
|
|||||||
dirName = linkName;
|
dirName = linkName;
|
||||||
|
|
||||||
while (argc-- >= 2) {
|
while (argc-- >= 2) {
|
||||||
#if 0
|
|
||||||
char srcName[BUFSIZ + 1];
|
|
||||||
int nChars;
|
|
||||||
#endif
|
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (strlen(*argv) > BUFSIZ) {
|
|
||||||
fprintf(stderr, name_too_long, "ln");
|
|
||||||
exit FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (followLinks == FALSE) {
|
|
||||||
strcpy(srcName, *argv);
|
|
||||||
} else {
|
|
||||||
/* Warning! This can silently truncate if > BUFSIZ, but
|
|
||||||
I don't think that there can be one > BUFSIZ anyway. */
|
|
||||||
nChars = readlink(*argv, srcName, BUFSIZ);
|
|
||||||
srcName[nChars] = '\0';
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (linkIntoDirFlag == TRUE) {
|
if (linkIntoDirFlag == TRUE) {
|
||||||
char *baseName = get_last_path_component(*argv);
|
char *baseName = get_last_path_component(*argv);
|
||||||
linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
|
linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
|
||||||
@ -155,7 +130,7 @@ extern int ln_main(int argc, char **argv)
|
|||||||
exit FALSE;
|
exit FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (linkIntoDirFlag)
|
if (linkIntoDirFlag == TRUE)
|
||||||
free(linkName);
|
free(linkName);
|
||||||
|
|
||||||
argv++;
|
argv++;
|
||||||
|
29
ln.c
29
ln.c
@ -92,13 +92,7 @@ extern int ln_main(int argc, char **argv)
|
|||||||
|
|
||||||
linkName = argv[argc - 1];
|
linkName = argv[argc - 1];
|
||||||
|
|
||||||
if (strlen(linkName) > BUFSIZ) {
|
linkIntoDirFlag = isDirectory(linkName, followLinks, NULL);
|
||||||
fprintf(stderr, name_too_long, "ln");
|
|
||||||
exit FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
linkIntoDirFlag = isDirectory(linkName, TRUE, NULL);
|
|
||||||
|
|
||||||
if ((argc >= 3) && linkIntoDirFlag == FALSE) {
|
if ((argc >= 3) && linkIntoDirFlag == FALSE) {
|
||||||
fprintf(stderr, not_a_directory, "ln", linkName);
|
fprintf(stderr, not_a_directory, "ln", linkName);
|
||||||
exit FALSE;
|
exit FALSE;
|
||||||
@ -108,27 +102,8 @@ extern int ln_main(int argc, char **argv)
|
|||||||
dirName = linkName;
|
dirName = linkName;
|
||||||
|
|
||||||
while (argc-- >= 2) {
|
while (argc-- >= 2) {
|
||||||
#if 0
|
|
||||||
char srcName[BUFSIZ + 1];
|
|
||||||
int nChars;
|
|
||||||
#endif
|
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (strlen(*argv) > BUFSIZ) {
|
|
||||||
fprintf(stderr, name_too_long, "ln");
|
|
||||||
exit FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (followLinks == FALSE) {
|
|
||||||
strcpy(srcName, *argv);
|
|
||||||
} else {
|
|
||||||
/* Warning! This can silently truncate if > BUFSIZ, but
|
|
||||||
I don't think that there can be one > BUFSIZ anyway. */
|
|
||||||
nChars = readlink(*argv, srcName, BUFSIZ);
|
|
||||||
srcName[nChars] = '\0';
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (linkIntoDirFlag == TRUE) {
|
if (linkIntoDirFlag == TRUE) {
|
||||||
char *baseName = get_last_path_component(*argv);
|
char *baseName = get_last_path_component(*argv);
|
||||||
linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
|
linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
|
||||||
@ -155,7 +130,7 @@ extern int ln_main(int argc, char **argv)
|
|||||||
exit FALSE;
|
exit FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (linkIntoDirFlag)
|
if (linkIntoDirFlag == TRUE)
|
||||||
free(linkName);
|
free(linkName);
|
||||||
|
|
||||||
argv++;
|
argv++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user