1
0
mirror of git://git.suckless.org/sbase synced 2024-12-23 07:25:07 +00:00

ln: try link first

This commit is contained in:
Connor Lane Smith 2011-06-22 23:45:03 +01:00
parent 2835d9ecda
commit 807d45aa80
2 changed files with 12 additions and 5 deletions

11
ln.c
View File

@ -34,7 +34,14 @@ main(int argc, char *argv[])
int int
ln(const char *s1, const char *s2) ln(const char *s1, const char *s2)
{ {
if(fflag && remove(s2) == -1 && errno != ENOENT) int (*flink)(const char *, const char *) = sflag ? symlink : link;
if(flink(s1, s2) == 0)
return 0;
if(fflag && errno == EEXIST) {
if(remove(s2) == -1)
eprintf("remove %s:", s2); eprintf("remove %s:", s2);
return (sflag ? symlink : link)(s1, s2); return flink(s1, s2);
}
return -1;
} }

View File

@ -44,7 +44,7 @@ fnck(const char *a, const char *b, int (*fn)(const char *, const char *))
if(stat(a, &sta) == 0 && stat(b, &stb) == 0 if(stat(a, &sta) == 0 && stat(b, &stb) == 0
&& sta.st_dev == stb.st_dev && sta.st_ino == stb.st_ino) && sta.st_dev == stb.st_dev && sta.st_ino == stb.st_ino)
eprintf("%s: same file as: %s\n", b, a); eprintf("%s -> %s: same file\n", a, b);
if(fn(a, b) == -1) if(fn(a, b) == -1)
eprintf("%s:", b); eprintf("%s -> %s:", a, b);
} }