fanf: (Default)
[personal profile] fanf

What happens if you try to create a symlink to a zero-length target, as in ln -s "" foo?

Linux: ENOENT.

Mac OS X 10.4: EINVAL.

FreeBSD: works, and any attempt to resolve the symlink returns ENOENT.

Solaris: works, and the resulting symlink behaves the same as ln -s . foo

Date: 2008-09-15 15:46 (UTC)
From: [identity profile] hoiho.livejournal.com
Cygwin (on XP): ln: creating symbolic link `foo' to `': No such file or directory

NetBSD: As FreeBSD

Date: 2008-09-15 15:55 (UTC)
From: [identity profile] filecoreinuse.livejournal.com
Does POSIX have a view on this?

Date: 2008-09-15 15:56 (UTC)
From: [identity profile] crazyscot.livejournal.com
OSX 10.3.9 - same as 10.4

Date: 2008-09-15 16:31 (UTC)
From: [identity profile] filecoreinuse.livejournal.com
Briefly looking at the symlink syscall in Linux at http://lxr.linux.no/linux+v2.6.26.5/fs/namei.c#L2447 it appears that the 'Right Thing' is done in that the first path is just passed 'as is' to the VFS layer meaning buggy behaviour can be blamed on the FS driver. This all assumes that GNU's libc doesn't 'sanitise' the input.

Date: 2008-09-15 16:46 (UTC)
simont: A picture of me in 2016 (Default)
From: [personal profile] simont
A quick strace ln -s "" zzz turns up
symlink("", "zzz")                      = -1 ENOENT (No such file or directory)
so it doesn't look as if glibc is doing anything obviously silly above the syscall level.

Date: 2008-09-15 16:57 (UTC)
From: [identity profile] techiebloke.livejournal.com
It might be interesting, then, to repeat the linux experiment with a variety of filesystems: eg UFS.

Date: 2008-09-15 20:10 (UTC)
From: [identity profile] zkzkz.livejournal.com
Huh, fascinating. My intuition led me to expect Solaris's behaviour.

Date: 2008-09-15 20:14 (UTC)
From: [identity profile] zkzkz.livejournal.com
So in trying to justify my intuition I found what I would consider a bug in Bash -- "set -P" shouldn't change the user-visible behaviour of "cd":

$ pwd
/tmp/foo
$ cd ""
$ set -P
$ cd ""
bash: cd: : No such file or directory

But really this is caused by the same disagreement. Bash is behaving as I would expect and assuming chdir("") is a noop. But Linux apparently gives an error.

Date: 2008-09-15 20:16 (UTC)
From: [identity profile] zkzkz.livejournal.com
(Well, except for the way it's documented to, namely the behaviour of ".." of course)

What an abomination, I wonder why I haven't turned it off yet.

July 2025

S M T W T F S
  1 2345
6789101112
13141516171819
20212223242526
2728293031  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated 2025-07-09 17:06
Powered by Dreamwidth Studios