|UNLINK(2)||System Calls Manual||UNLINK(2)|
— remove directory entry
fd, const char
unlink() function removes the link
named by path from its directory and decrements the
link count of the file which was referenced by the link. If that decrement
reduces the link count of the file to zero, and no process has the file
open, then all resources associated with the file are reclaimed. If one or
more processes have the file open when the last link is removed, the link is
removed, but the removal of the file is delayed until all references to it
have been closed.
unlinkat() function is equivalent to
rmdir(2) function depending on the value
of flag (see below), except that where
path specifies a relative path, the directory entry to
be removed is determined relative to the directory associated with file
descriptor fd instead of the current working
unlinkat() is passed the special value
AT_FDCWD (defined in
<fcntl.h>) in the
fd parameter, the current working directory is used
and the behavior is identical to a call to
or rmdir(2), depending on whether or not
AT_REMOVEDIR bit is set in
The flag argument is the bitwise OR of zero or more of the following values:
Upon successful completion, the value 0 is returned; otherwise the value -1 is returned and the global variable errno is set to indicate the error.
unlinkat() functions will fail if:
NAME_MAXcharacters, or an entire pathname (including the terminating NUL) exceeded
unlink() on a directory.
unlinkat() will fail if:
AT_REMOVEDIRflag bit is set and path does not name a directory.
AT_REMOVEDIRflag bit is set and the named directory contains files other than ‘
.’ and ‘
..’ in it.
AT_REMOVEDIRand the last element of path consists of ‘
AT_FDCWDnor a valid file descriptor.
unlinkat() functions conform to
IEEE Std 1003.1-2008 (“POSIX.1”).
unlink() system call first appeared in
Version 1 AT&T UNIX. The
unlinkat() function appeared in
|June 1, 2016||OpenBSD-current|