1
0
mirror of git://git.suckless.org/sbase synced 2024-12-24 07:53:08 +00:00
sbase/ln.c

41 lines
728 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"
2011-06-04 01:56:18 +00:00
static int ln(const char *, const char *);
static bool sflag = false;
static bool fflag = false;
2011-05-24 12:00:30 +00:00
int
main(int argc, char *argv[])
{
char c;
2011-06-04 01:56:18 +00:00
while((c = getopt(argc, argv, "fs")) != -1)
2011-05-24 12:00:30 +00:00
switch(c) {
2011-06-04 01:56:18 +00:00
case 'f':
fflag = true;
break;
2011-05-24 12:00:30 +00:00
case 's':
sflag = true;
break;
default:
exit(EXIT_FAILURE);
}
2011-06-04 01:56:18 +00:00
enmasse(argc - optind, &argv[optind], ln);
2011-05-24 12:00:30 +00:00
return EXIT_SUCCESS;
}
2011-06-04 01:56:18 +00:00
int
ln(const char *s1, const char *s2)
{
2011-06-04 11:20:41 +00:00
if(fflag && remove(s2) == -1 && errno != ENOENT)
2011-06-04 01:56:18 +00:00
eprintf("remove %s:", s2);
return (sflag ? symlink : link)(s1, s2);
}