made note of my recent changes
[oweals/busybox.git] / ln.c
diff --git a/ln.c b/ln.c
index cd3cb4e450f86e12caa3b1ca48f183c8e29e8df2..60fe394386a8a7f7a3441da9e4f6ba8cb0dab6e2 100644 (file)
--- a/ln.c
+++ b/ln.c
@@ -1,7 +1,9 @@
 /*
  * Mini ln implementation for busybox
  *
- * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
+ *
+ * Copyright (C) 1999 by Lineo, inc.
+ * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <errno.h>
 
 
-static const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n"
-"\n"
-"\tAdd a new name that refers to the same file as \"original-name\"\n"
-"\n"
-"\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n"
-"\t-f:\tRemove existing destination files.\n";
+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"
+"Options:\n"
+"\t-s\tmake symbolic links instead of hard links\n"
+"\t-f\tremove existing destination files\n";
 
 
 static int symlinkFlag = FALSE;
 static int removeoldFlag = FALSE;
-static const char *destName;
 
 
 extern int ln_main(int argc, char **argv)
 {
     int status;
-    char newdestName[NAME_MAX];
+    static char* linkName;
 
     if (argc < 3) {
-       fprintf(stderr, "Usage: %s", ln_usage);
-       exit (FALSE);
+       usage (ln_usage);
     }
     argc--;
     argv++;
@@ -61,38 +60,34 @@ extern int ln_main(int argc, char **argv)
                removeoldFlag = TRUE;
                break;
            default:
-               fprintf(stderr, "Usage: %s\n", ln_usage);
-               exit(FALSE);
+               usage (ln_usage);
            }
        argc--;
        argv++;
     }
 
 
-    destName = argv[argc - 1];
+    linkName = argv[argc - 1];
 
-    if ((argc > 3) && !(isDirectory(destName))) {
-       fprintf(stderr, "%s: not a directory\n", destName);
+    if ((argc > 3) && !(isDirectory(linkName))) {
+       fprintf(stderr, "%s: not a directory\n", linkName);
        exit (FALSE);
     }
 
     while (argc-- >= 2) {
-       strcpy(newdestName, destName);
-       strcat(newdestName, (*argv)+(strlen(*(++argv))));
-       
        if (removeoldFlag==TRUE ) {
-           status = ( unlink(newdestName) && errno != ENOENT );
+           status = ( unlink(linkName) && errno != ENOENT );
            if ( status != 0 ) {
-               perror(newdestName);
+               perror(linkName);
                exit( FALSE);
            }
        }
        if ( symlinkFlag==TRUE)
-               status = symlink(*argv, newdestName);
+               status = symlink(*argv, linkName);
        else
-               status = link(*argv, newdestName);
+               status = link(*argv, linkName);
        if ( status != 0 ) {
-           perror(newdestName);
+           perror(linkName);
            exit( FALSE);
        }
     }