The Linux Programming Interface

(nextflipdebug5) #1
Directories and Links 345

Given the pathname of an existing file in oldpath, the link() system call creates a new
link, using the pathname specified in newpath. If newpath already exists, it is not
overwritten; instead, an error (EEXIST) results.
On Linux, the link() system call doesn’t dereference symbolic links. If oldpath is
a symbolic link, then newpath is created as a new hard link to the same symbolic link
file. (In other words, newpath is also a symbolic link to the same file to which oldpath
refers.) This behavior doesn’t conform to SUSv3, which says that all functions that
perform pathname resolution should dereference symbolic links unless other-
wise specified (and there is no exception specified for link()). Most other UNIX


Table 18-1: Interpretation of symbolic links by various functions


Function Follows links? Notes
access() z
acct() z
bind() z UNIX domain sockets have pathnames
chdir() z
chmod() z
chown() z
chroot() z
creat() z
exec() z
getxattr() z
lchown()
lgetxattr()
link() See Section 18.3
listxattr() z
llistxattr()
lremovexattr()
lsetxattr()
lstat()
lutimes()
open() z Unless O_NOFOLLOW or O_EXCL | O_CREAT specified
opendir() z
pathconf() z
pivot_root() z
quotactl() z
readlink()
removexattr() z
rename() Links are not followed in either argument
rmdir() Fails with ENOTDIR if argument is a symbolic link
setxattr() z
stat() z
statfs(), statvfs() z
swapon(), swapoff() z
truncate() z
unlink()
uselib() z
utime(), utimes() z
Free download pdf