sbase/ln.c

44 lines
705 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>
2011-05-24 12:00:30 +00:00
#include <stdbool.h>
2011-06-04 01:56:18 +00:00
#include <stdio.h>
2011-05-24 12:00:30 +00:00
#include <stdlib.h>
#include <unistd.h>
#include "util.h"
2013-06-14 18:20:47 +00:00
static void
usage(void)
{
eprintf("usage: %s [-fs] target linkname\n", argv0);
}
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;
bool sflag = false;
bool fflag = false;
2013-06-14 18:20:47 +00:00
ARGBEGIN {
case 'f':
fflag = true;
break;
case 's':
sflag = true;
break;
default:
usage();
} ARGEND;
2014-02-17 11:41:37 +00:00
flink = sflag ? symlink : link;
fname = sflag ? "symlink" : "link";
if (fflag == true)
remove(argv[1]);
if (flink(argv[0], argv[1]) < 0)
eprintf("%s:", fname);
2013-06-14 18:20:47 +00:00
return EXIT_SUCCESS;
2011-05-24 12:00:30 +00:00
}