Fix a completely broken ln(1)

This commit is contained in:
sin 2014-10-17 16:03:41 +01:00
parent 0cc3beb739
commit 353ac69a93

17
ln.c
View File

@ -1,10 +1,11 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <errno.h> #include <errno.h>
#include <libgen.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "util.h" #include "util.h"
static void static void
@ -32,6 +33,9 @@ main(int argc, char *argv[])
usage(); usage();
} ARGEND; } ARGEND;
if (argc == 0 || argc > 2)
usage();
if (sflag) { if (sflag) {
flink = symlink; flink = symlink;
fname = "symlink"; fname = "symlink";
@ -40,17 +44,12 @@ main(int argc, char *argv[])
fname = "link"; fname = "link";
} }
if(argc < 2) { to = argc < 2 ? basename(argv[0]) : argv[1];
if((to = strrchr(argv[0], '/')))
to++;
} else {
to = argv[1];
}
if (fflag == true) if (fflag == true)
remove(argv[1]); remove(to);
if (flink(argv[0], to) < 0) if (flink(argv[0], to) < 0)
eprintf("%s:", fname); eprintf("%s %s <- %s:", fname, argv[0], to);
return 0; return 0;
} }