sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 9e04a4fcdc394b82b290b5dc6c825c17340b705f
parent d38361245097d1903eb9ef55c843bdef6a621f38
Author: Eivind Uggedal <eivind@uggedal.com>
Date:   Fri,  5 Jun 2015 11:11:09 +0000

ln: allow dangling symlinks

Diffstat:
Mln.c | 25++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/ln.c b/ln.c @@ -65,20 +65,23 @@ main(int argc, char *argv[]) if (!hastarget) target = basename(*argv); - if (stat(*argv, &st) < 0) { - weprintf("stat %s:", *argv); - ret = 1; - continue; - } else if (fstatat(dirfd, target, &tst, AT_SYMLINK_NOFOLLOW) < 0) { - if (errno != ENOENT) { - weprintf("fstatat %s %s:", targetdir, target); + if (!sflag) { + if (stat(*argv, &st) < 0) { + weprintf("stat %s:", *argv); + ret = 1; + continue; + } else if (fstatat(dirfd, target, &tst, AT_SYMLINK_NOFOLLOW) < 0) { + if (errno != ENOENT) { + weprintf("fstatat %s %s:", targetdir, target); + ret = 1; + continue; + } + } else if (st.st_dev == tst.st_dev && st.st_ino == tst.st_ino) { + weprintf("%s and %s/%s are the same file\n", + *argv, targetdir, target); ret = 1; continue; } - } else if (st.st_dev == tst.st_dev && st.st_ino == tst.st_ino) { - weprintf("%s and %s/%s are the same file\n", *argv, targetdir, target); - ret = 1; - continue; } if (fflag && unlinkat(dirfd, target, 0) < 0 && errno != ENOENT) {