Open System Services System Calls Reference Manual (G06.25+, H06.03+)

System Functions (k - m) link(2)
NAME
link - Creates an additional directory entry for an existing le on the current leset
LIBRARY
G-series native OSS processes: system library
H-series OSS processes: implicit libraries
SYNOPSIS
#include <unistd.h>
int link(
const char *path1,
const char *path2);
PARAMETERS
path1 Points to the pathname of an existing le.
If any component of the path1 parameter refers to a symbolic link, the link is
traversed and pathname resolution continues.
path2 Points to the pathname for the directory entry to be created.
If any component of the path2 parameter refers to a symbolic link, the link is
traversed and pathname resolution continues.
If the nal component of the path2 parameter refers to an existing entity, the call
fails and errno is set to [EEXIST].
DESCRIPTION
The link() function creates an additional hard link (directory entry) for an existing le. Both the
old and the new link share equal access rights to the underlying le. The link() function atomi-
cally creates a new link for the existing le and increments the link count of the le by 1.
The pathnames pointed to by both the path1 and path2 parameters must reside on the same
leset. If this is not the case, errno is set to [EXDEV].
The path1 parameter must not name a directory; a hard link to a directory cannot be created.
Attempting to create a link to a directory fails. The value -1 is returned and errno is set to
[EPERM].
Attempting to create a link to /dev/tty or /dev/null or attempting to create a link in the root direc-
tory of an OSS leset to a le named lost+found fails and causes errno to be set to [EPERM].
The calling process requires the following:
Execute (search) permission on the directory containing the existing le.
Execute (search) and write permission on the directory into which the link is being
added.
Upon successful completion, the link() function marks the st_ctime eld of the le for update
and marks the st_ctime and st_mtime elds of the directory containing the new entry for update.
527186-003 Hewlett-Packard Company 45