2 * Mini ln implementation for busybox
5 * Copyright (C) 1999 by Lineo, inc.
6 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 static const char ln_usage[] = "ln [-s] [-f] original-name additional-name\n"
32 "\tAdd a new name that refers to the same file as \"original-name\"\n"
34 "\t-s:\tUse a \"symbolic\" link, instead of a \"hard\" link.\n"
35 "\t-f:\tRemove existing destination files.\n";
38 static int symlinkFlag = FALSE;
39 static int removeoldFlag = FALSE;
40 static const char *destName;
43 extern int ln_main(int argc, char **argv)
46 char newdestName[NAME_MAX];
54 /* Parse any options */
55 while (**argv == '-') {
72 destName = argv[argc - 1];
74 if ((argc > 3) && !(isDirectory(destName))) {
75 fprintf(stderr, "%s: not a directory\n", destName);
80 strcpy(newdestName, destName);
81 strcat(newdestName, (*argv)+(strlen(*(++argv))));
83 if (removeoldFlag==TRUE ) {
84 status = ( unlink(newdestName) && errno != ENOENT );
90 if ( symlinkFlag==TRUE)
91 status = symlink(*argv, newdestName);
93 status = link(*argv, newdestName);