sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 81bb8422a534456d9afe0aa61bb09c94c62f9398
parent 72b909df9cf9ff8df1bb9e88e7fd4f6597d7647f
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Thu, 10 Jul 2014 21:00:02 +0000

ln: allow with one argument

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
Mln.c | 23++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/ln.c b/ln.c @@ -4,19 +4,20 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <string.h> #include "util.h" static void usage(void) { - eprintf("usage: %s [-fs] target linkname\n", argv0); + eprintf("usage: %s [-fs] target [linkname]\n", argv0); } int main(int argc, char *argv[]) { int (*flink)(const char *, const char *); - char *fname; + char *fname, *to; bool sflag = false; bool fflag = false; @@ -31,12 +32,24 @@ main(int argc, char *argv[]) usage(); } ARGEND; - flink = sflag ? symlink : link; - fname = sflag ? "symlink" : "link"; + if(sflag) { + flink = symlink; + fname = "symlink"; + } else { + flink = link; + fname = "link"; + } + + if(argc < 2) { + if((to = strrchr(argv[0], '/'))) + to++; + } else { + to = argv[1]; + } if (fflag == true) remove(argv[1]); - if (flink(argv[0], argv[1]) < 0) + if (flink(argv[0], to) < 0) eprintf("%s:", fname); return EXIT_SUCCESS;