This was broken in multiple ways. For instance, the overlay-
check of identical files (name and target) was omitted for
symbolic links for some reason.
While at it, I fixed the stat-handling, improved the error-
messages so the right paths were shown and removed the
illegimite bail-out when the target-fstatat failed (we want
only a warning here as well).
This allows for creating dangling symlinks with force applied:
# Before:
$ ln -sf non-existant target
ln: stat non-existent: No such file or directory
$ ls -l target
ls: lstat target: No such file or directory
# After:
$ ln -sf non-existant target
$ ls -l target
lrwxrwxrwx 1 eu users 12 May 08 07:50 target -> non-existent
This also allows creating relative non-dangling symlinks with force applied:
touch existant; mkdir dir
# Before
$ ln -sf ../existant dir
ln: stat ../existant: No such file or directory
$ ls -l dir
# After
$ ln -sf ../existant dir
$ ls -l dir
lrwxrwxrwx 1 eu users 11 May 08 07:53 existant -> ../existant
The check for whether each src and to pairs are on the same device with the
same inode are only needed for hardlinks so that a forcefull link does
not remove the underlying file:
touch f; mkdir dir
# Before:
$ ln -f f f dir
ln: f and f are the same file
$ ls -i f dir/f
3670611 dir/f
3670611 f
# After:
$ ln -f f f dir
ln: f and f are the same file
$ ls -i f dir/f
4332236 dir/f
4332236 f
1) Clarify behaviour when the f-flag is given and a target is in its
own way.
2) Fix usage()-style.
3) Group local variable declarations.
4) reorder args
5) argc style, other boolean style changes
6) improve error messages
7) set argv[argc - 1] to NULL to allow argv-centric loop later
8) BUGFIX: POSIX specifies that when with the f-flag there's a
situation where a file stands in its own way for linking it
should be ignored.
9) Add weprintf() where possible, so we don't pussy out when there's
a small issue. This is sbase ffs!
It actually makes the binaries smaller, the code easier to read
(gems like "val == true", "val == false" are gone) and actually
predictable in the sense of that we actually know what we're
working with (one bitwise operator was quite adventurous and
should now be fixed).
This is also more consistent with the other suckless projects
around which don't use boolean types.