[hackers] [sbase] ln: allow with one argument || Hiltjo Posthuma
commit 81bb8422a534456d9afe0aa61bb09c94c62f9398
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Thu Jul 10 21:00:02 2014 +0000
ln: allow with one argument
Signed-off-by: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
diff --git a/ln.c b/ln.c
index 029bce5..ef0ff79 100644
--- a/ln.c
+++ b/ln.c
_AT_@ -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
", argv0);
+ eprintf("usage: %s [-fs] target [linkname]
", argv0);
}
int
main(int argc, char *argv[])
{
int (*flink)(const char *, const char *);
- char *fname;
+ char *fname, *to;
bool sflag = false;
bool fflag = false;
_AT_@ -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;
Received on Mon Jul 21 2014 - 17:44:10 CEST
This archive was generated by hypermail 2.3.0
: Mon Jul 21 2014 - 17:48:21 CEST