summaryrefslogtreecommitdiff
path: root/ln.c
diff options
context:
space:
mode:
Diffstat (limited to 'ln.c')
-rw-r--r--ln.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/ln.c b/ln.c
index 4f30824..6929bfa 100644
--- a/ln.c
+++ b/ln.c
@@ -47,6 +47,14 @@ static int ln(const char *path, int dirfd, const char *target, int sym, int forc
fprintf(stderr, "ln: %s: %s\n", target, strerror(EEXIST));
return 1;
}
+
+ struct stat s2;
+ if (stat(path, &s2) == 0) {
+ if (st.st_dev == s2.st_dev && st.st_ino == s2.st_ino) {
+ fprintf(stderr, "ln: %s -> %s: same file\n", path, target);
+ return 1;
+ }
+ }
if (unlinkat(dirfd, target, 0) != 0) {
fprintf(stderr, "ln: %s: %s\n", target, strerror(errno));