Update internal.h to conditionally include asm/string.h
[oweals/busybox.git] / ln.c
diff --git a/ln.c b/ln.c
index eb7c99608cbd64d172e59fabfa13d94e559eb008..2233a1d68d032d318d13cd6e43ae745e34526d2b 100644 (file)
--- a/ln.c
+++ b/ln.c
 #include <errno.h>
 
 static const char ln_usage[] =
-       "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
-       "Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
+       "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\n"
        "Options:\n"
        "\t-s\tmake symbolic links instead of hard links\n"
 
        "\t-f\tremove existing destination files\n"
-       "\t-n\tno dereference symlinks - treat like normal file\n";
+       "\t-n\tno dereference symlinks - treat like normal file\n"
+#endif
+       ;
 
 static int symlinkFlag = FALSE;
 static int removeoldFlag = FALSE;
@@ -48,31 +51,40 @@ extern int ln_main(int argc, char **argv)
 {
        char *linkName;
        int linkIntoDirFlag;
+       int stopIt = FALSE;
 
-       if (argc < 3) {
-               usage(ln_usage);
-       }
        argc--;
        argv++;
 
        /* Parse any options */
-       while (**argv == '-') {
-               while (*++(*argv))
-                       switch (**argv) {
-                       case 's':
-                               symlinkFlag = TRUE;
-                               break;
-                       case 'f':
-                               removeoldFlag = TRUE;
-                               break;
-                       case 'n':
-                               followLinks = FALSE;
-                               break;
-                       default:
-                               usage(ln_usage);
-                       }
-               argc--;
-               argv++;
+       while (argc > 0 && stopIt == FALSE) {
+               if (**argv == '-') {
+                       while (*++(*argv))
+                               switch (**argv) {
+                                       case 's':
+                                               symlinkFlag = TRUE;
+                                               break;
+                                       case 'f':
+                                               removeoldFlag = TRUE;
+                                               break;
+                                       case 'n':
+                                               followLinks = FALSE;
+                                               break;
+                                       case '-':
+                                               stopIt = TRUE;
+                                               break;
+                                       default:
+                                               usage(ln_usage);
+                               }
+                       argc--;
+                       argv++;
+               }
+               else
+                       break;
+       }
+
+       if (argc < 2) {
+               usage(ln_usage);
        }
 
        linkName = argv[argc - 1];
@@ -84,7 +96,7 @@ extern int ln_main(int argc, char **argv)
 
        linkIntoDirFlag = isDirectory(linkName, TRUE, NULL);
 
-       if ((argc > 3) && !linkIntoDirFlag) {
+       if ((argc >= 3) && linkIntoDirFlag == FALSE) {
                fprintf(stderr, not_a_directory, "ln", linkName);
                exit FALSE;
        }
@@ -124,7 +136,7 @@ extern int ln_main(int argc, char **argv)
                        exit FALSE;
                }
        }
-       exit TRUE;
+       return( TRUE);
 }
 
 /*