Fix looping bug, use fullRead
[oweals/busybox.git] / coreutils / ln.c
index beaa58fac52c5f010bc8e4b080c47c1c78101951..d5f44ea4c363e344462790af2f79d69acdf49c47 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "internal.h"
 #define BB_DECLARE_EXTERN
-#define bb_need_name_too_long
 #define bb_need_not_a_directory
 #include "messages.c"
 
 #include <dirent.h>
 #include <errno.h>
 
-static const char ln_usage[] =
-       "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n"
-#ifndef BB_FEATURE_TRIVIAL_HELP
-       "\nCreate a link named LINK_NAME or DIRECTORY to the specified TARGET\n"
-       "\nYou may use '--' to indicate that all following arguments are non-options.\n\n"
-       "Options:\n"
-       "\t-s\tmake symbolic links instead of hard links\n"
-
-       "\t-f\tremove existing destination files\n"
-#if 0
-       "\t-n\tno dereference symlinks - treat like normal file\n"
-#endif
-#endif
-       ;
-
 static int symlinkFlag = FALSE;
 static int removeoldFlag = FALSE;
 static int followLinks = TRUE;
 
 extern int ln_main(int argc, char **argv)
 {
-       char *linkName, *dirName;
+       char *linkName, *dirName=NULL;
        int linkIntoDirFlag;
        int stopIt = FALSE;
 
@@ -92,15 +76,9 @@ extern int ln_main(int argc, char **argv)
 
        linkName = argv[argc - 1];
 
-       if (strlen(linkName) > BUFSIZ) {
-               fprintf(stderr, name_too_long, "ln");
-               exit FALSE;
-       }
-
-       linkIntoDirFlag = isDirectory(linkName, TRUE, NULL);
-
+       linkIntoDirFlag = isDirectory(linkName, followLinks, NULL);
        if ((argc >= 3) && linkIntoDirFlag == FALSE) {
-               fprintf(stderr, not_a_directory, "ln", linkName);
+               errorMsg(not_a_directory, linkName);
                exit FALSE;
        }
 
@@ -108,30 +86,11 @@ extern int ln_main(int argc, char **argv)
                dirName = linkName;
 
        while (argc-- >= 2) {
-#if 0
-               char srcName[BUFSIZ + 1];
-               int nChars;
-#endif
                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) {
                        char *baseName = get_last_path_component(*argv);
-                       linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
+                       linkName = (char *)xmalloc(strlen(dirName)+strlen(baseName)+2);
                        strcpy(linkName, dirName);
                        if(dirName[strlen(dirName)-1] != '/')
                                strcat(linkName, "/");
@@ -155,7 +114,7 @@ extern int ln_main(int argc, char **argv)
                        exit FALSE;
                }
 
-               if (linkIntoDirFlag)
+               if (linkIntoDirFlag == TRUE)
                        free(linkName);
 
                argv++;