link()

create link 

Function


SYNOPSIS

#include <unistd.h>

int link(const char *pathname1, const char *pathname2);


DESCRIPTION

The link() function creates a new path name to an existing file. The link() function atomically creates a new link for the existing file and increments the link count of the file by one.

If the existing file specifies a directory, link() returns -1 with errno set to EPERM.

Upon successful completion, link() marks for update the st_ctime field of the file. If link() fails, no link is created and the link count of the file remains unchanged.


PARAMETERS

pathname1 

Points to a path name that names an existing file.

pathname2 

Points to a path name that names the new directory entry to be created.


RETURN VALUES

If successful, link() returns a value of zero. On failure, it returns a value of -1 and sets errno to one of the following values:

EACCES 

A component of either path name prefix denies search permission.

The calling process does not have permission to access the existing file.

The requested link requires writing in a directory with a mode that denies write permission.

EEXIST 

The link named by pathname2 exists.

EFAULT 

The pathname1 or pathname2 parameter is an invalid pointer.

EINTR 

A signal interrupted the call.

EMLINK 

The number of links to the file exceeds LINK_MAX.

ENAMETOOLONG 

The length of pathname1 or pathname2 string exceeds PATH_MAX or a path name component is longer than NAME_MAX.

ENOENT 

A component of either path name prefix does not exist.

Either pathname1 or pathname2 points to an empty string.

The file named by pathname1 does not exist.

ENOSPC 

The directory that would contain the link cannot be extended.

ENOTDIR 

A component of either path name prefix is not a directory.

EPERM 

The file that pathname1 named is a directory,.

EROFS 

The requested link requires writing in a directory on a read-only file system.

EXDEV 

The link named by pathname2 and the file named by pathname1 are on different file systems (logical drives), and the implementation does not support links between file systems.


CONFORMANCE

POSIX.1 (1996), with exceptions.


MULTITHREAD SAFETY LEVEL

Async-signal-safe.


PORTING ISSUES

Windows only supports hard links between files on local NTFS partitions. Calls to link() on any other type of file system fails with errno set to EMLINK.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
rename(), symlink(), unlink()


PTC MKS Toolkit 10.2 Documentation Build 28.