[hackers] [sbase] ln: allow dangling symlinks || Eivind Uggedal

From: <git_AT_suckless.org>
Date: Sun, 7 Jun 2015 10:09:47 +0200 (CEST)

commit 9e04a4fcdc394b82b290b5dc6c825c17340b705f
Author: Eivind Uggedal <eivind_AT_uggedal.com>
Date: Fri Jun 5 11:11:09 2015 +0000

    ln: allow dangling symlinks

diff --git a/ln.c b/ln.c
index 6e40c8f..ef3997c 100644
--- a/ln.c
+++ b/ln.c
_AT_@ -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) {
Received on Sun Jun 07 2015 - 10:09:47 CEST

This archive was generated by hypermail 2.3.0 : Thu Jun 18 2015 - 17:36:30 CEST