2011-05-24 08:00:30 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2011-06-03 21:56:18 -04:00
|
|
|
#include <errno.h>
|
2014-10-17 11:03:41 -04:00
|
|
|
#include <libgen.h>
|
2011-05-24 08:00:30 -04:00
|
|
|
#include <stdbool.h>
|
2011-06-03 21:56:18 -04:00
|
|
|
#include <stdio.h>
|
2011-05-24 08:00:30 -04:00
|
|
|
#include <stdlib.h>
|
2014-07-10 17:00:02 -04:00
|
|
|
#include <string.h>
|
2014-10-17 11:03:41 -04:00
|
|
|
#include <unistd.h>
|
2014-11-13 12:29:30 -05:00
|
|
|
|
2011-05-24 08:00:30 -04:00
|
|
|
#include "util.h"
|
|
|
|
|
2013-06-14 14:20:47 -04:00
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2014-07-10 17:00:02 -04:00
|
|
|
eprintf("usage: %s [-fs] target [linkname]\n", argv0);
|
2013-06-14 14:20:47 -04:00
|
|
|
}
|
|
|
|
|
2011-05-24 08:00:30 -04:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2014-02-17 06:41:37 -05:00
|
|
|
int (*flink)(const char *, const char *);
|
2014-07-10 17:00:02 -04:00
|
|
|
char *fname, *to;
|
2014-02-17 06:41:37 -05:00
|
|
|
bool sflag = false;
|
|
|
|
bool fflag = false;
|
|
|
|
|
2013-06-14 14:20:47 -04:00
|
|
|
ARGBEGIN {
|
|
|
|
case 'f':
|
|
|
|
fflag = true;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
sflag = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
2014-10-17 11:03:41 -04:00
|
|
|
if (argc == 0 || argc > 2)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
if (sflag) {
|
2014-07-10 17:00:02 -04:00
|
|
|
flink = symlink;
|
|
|
|
fname = "symlink";
|
|
|
|
} else {
|
|
|
|
flink = link;
|
|
|
|
fname = "link";
|
|
|
|
}
|
|
|
|
|
2014-10-17 11:03:41 -04:00
|
|
|
to = argc < 2 ? basename(argv[0]) : argv[1];
|
2014-02-17 06:41:37 -05:00
|
|
|
|
|
|
|
if (fflag == true)
|
2014-10-17 11:03:41 -04:00
|
|
|
remove(to);
|
2014-07-10 17:00:02 -04:00
|
|
|
if (flink(argv[0], to) < 0)
|
2014-10-17 11:03:41 -04:00
|
|
|
eprintf("%s %s <- %s:", fname, argv[0], to);
|
2013-06-14 14:20:47 -04:00
|
|
|
|
2014-10-02 18:46:04 -04:00
|
|
|
return 0;
|
2011-05-24 08:00:30 -04:00
|
|
|
}
|