ln: allow with one argument
Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>
This commit is contained in:
parent
72b909df9c
commit
81bb8422a5
23
ln.c
23
ln.c
|
@ -4,19 +4,20 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
eprintf("usage: %s [-fs] target linkname\n", argv0);
|
eprintf("usage: %s [-fs] target [linkname]\n", argv0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int (*flink)(const char *, const char *);
|
int (*flink)(const char *, const char *);
|
||||||
char *fname;
|
char *fname, *to;
|
||||||
bool sflag = false;
|
bool sflag = false;
|
||||||
bool fflag = false;
|
bool fflag = false;
|
||||||
|
|
||||||
|
@ -31,12 +32,24 @@ main(int argc, char *argv[])
|
||||||
usage();
|
usage();
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
|
||||||
flink = sflag ? symlink : link;
|
if(sflag) {
|
||||||
fname = sflag ? "symlink" : "link";
|
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)
|
if (fflag == true)
|
||||||
remove(argv[1]);
|
remove(argv[1]);
|
||||||
if (flink(argv[0], argv[1]) < 0)
|
if (flink(argv[0], to) < 0)
|
||||||
eprintf("%s:", fname);
|
eprintf("%s:", fname);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user