UNLINK(2) BSD UNLINK(2)
NAME
unlink - remove directory entry
SYNOPSIS
unlink(path)
char *path;
DESCRIPTION
unlink removes the entry for the file path from its directory. If this
entry was the last link to the file and no process has the file open, the
system reclaims all resources associated with the file. If a process has
the file open, the system waits until the file is closed before
reclaiming resources, even though the directory entry has disappeared.
ERRORS
The unlink succeeds unless any of the following are true:
[ENOTDIR] A component of the path prefix is not a directory.
[ENAMETOOLONG] A component of a pathname exceeded 255 characters, or an
entire pathname exceeded 1023 characters.
[ENOENT] The named file does not exist.
[EACCES] Search permission is denied for a component of the path
prefix.
[EACCES] Write permission is denied on the directory containing
the link to be removed.
[ELOOP] Too many symbolic links were encountered in translating
the pathname.
[EPERM] The named file is a directory and the effective user ID
of the process is not the super-user.
[EBUSY] The entry to be unlinked is the mount point for a
mounted file system.
[EIO] An I/O error occurred while deleting the directory entry
or deallocating the inode.
[EROFS] The named file resides on a read-only file system.
[EFAULT] path points outside the process' allocated address
space.
SEE ALSO
close(2), link(2), rmdir(2)
DIAGNOSTICS
A successful call returns 0. A failed call returns -1 and sets errno as
indicated under "Errors."
NOTES
Under other implementations, unlink fails if either of the following is
true:
[EINVAL] The pathname contains a character with the high-order
bit set.
[EPERM] The directory containing the file is marked "sticky,"
and neither the containing directory nor the file to be
removed are owned by the effective user ID.