1
0
mirror of git://git.suckless.org/sbase synced 2024-12-29 02:22:27 +00:00
sbase/ln.c

56 lines
827 B
C
Raw Normal View History

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