UNLINK(2V)

NAME
unlink - remove directory entry

SYNOPSIS
int unlink(path)
char *path;

DESCRIPTION

unlink() removes the directory entry named by the pathname pointed to by path and decrements the link count of the file referred to by that entry. If this entry was the last link to the file, and no process has the file open, then all resources associated with the file are reclaimed. If, however, the file was open in any process, the actual resource reclamation is delayed until it is closed, even though the directory entry has disappeared.

If path refers to a directory, the effective user-ID of the calling process must be super-user.

Upon successful completion, unlink() marks for update the st_ctime and st_mtime fields of the parent directory. Also, if the file's link count is not zero, the st_ctime field of the file is marked for update.

RETURN VALUES

unlink() returns:

0   on success.

-1  on failure and sets errno to indicate the error.

ERRORS

EACCES
    Search permission is denied for a component of the path prefix of path.

    Write permission is denied for the directory containing the link to be removed.

EBUSY
    The entry to be unlinked is the mount point for a mounted file system.

EFAULT
    path points outside the process's allocated address space.

EINVAL
    The file referred to by path is the current directory, `.'.

EIO An I/O error occurred while reading from or writing to the file system.

ELOOP
    Too many symbolic links were encountered in translating path.

ENAMETOOLONG
    The length of the path argument exceeds {PATH_MAX}.

    A pathname component is longer than {NAME_MAX} while {_POSIX_NO_TRUNC} is in effect (see pathconf(2V)).

ENOENT
    The file referred to by path does not exist.

ENOTDIR
    A component of the path prefix of path is not a directory.

EPERM
    The file referred to by path is a directory and the effective user ID of the process is not the super-user.

EROFS
    The file referred to by path resides on a read-only file system.

SYSTEM V ERRORS

In addition to the above, the following may also occur:

ENOENT
    path points to an empty string.

SEE ALSO
close(2V), link(2V), rmdir(2V)

NOTES

Applications should use rmdir(2V) to remove directories. Although root may use unlink() on directories, all users may use rmdir().