| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 2: System Calls Oracle Solaris 11 Information Library |
- remove directory entry
#include <unistd.h>intunlink(const char *path);
intunlinkat(intdirfd,const char *path,intflag);
Theunlink() function removes a link to a file. Ifpath namesa symbolic link,unlink() removes the symbolic link named bypath anddoes not affect any file or directory named by the contents ofthe symbolic link. Otherwise,unlink() removes the link named by the pathnamepointed to bypath and decrements the link count of the filereferenced by the link.
Theunlinkat() function also removes a link to a file. Seefsattr(5).If theflag argument is 0, the behavior ofunlinkat() is the sameasunlink() except in the processing of itspath argument. Ifpathis absolute,unlinkat() behaves the same asunlink() and thedirfd argument isunused. Ifpath is relative anddirfd has the valueAT_FDCWD, definedin <fcntl.h>,unlinkat() also behaves the same asunlink(). Otherwise,path is resolvedrelative to the directory referenced by thedirfd argument.
If theflag argument is set to the valueAT_REMOVEDIR, defined in<fcntl.h>,unlinkat() behaves the same asrmdir(2) except in the processing ofthepath argument as described above.
When the file's link count becomes 0 and no process has thefile open, the space occupied by the file will be freed andthe file is no longer accessible. If one or more processes havethe file open when the last link is removed, the link isremoved beforeunlink() orunlinkat() returns, but the removal of the filecontents is postponed until all references to the file are closed.
If thepath argument is a directory and the filesystem supportsunlink()andunlinkat() on directories, the directory is unlinked from its parent withno cleanup being performed. In UFS, the disconnected directory will befound the next time the filesystem is checked withfsck(1M). Theunlink() andunlinkat() functions will not fail simply because a directory is not empty. Theuser with appropriate privileges can orphan a non-empty directory without generating anerror message.
If thepath argument is a directory and the filesystem does notsupportunlink() andunlink() on directories (for example, ZFS), the call willfail witherrno set toEPERM.
Upon successful completion,unlink() andunlinkat() will mark for update thest_ctimeandst_mtime fields of the parent directory. If the file's linkcount is not 0, thest_ctime field of the file will be markedfor update.
Upon successful completion,0 is returned. Otherwise,-1 is returned,errnois set to indicate the error, and the file is not unlinked.
Theunlink() andunlinkat() functions will fail if:
Search permission is denied for a component of thepath prefix, or write permission is denied on the directory containing the link to be removed.
The parent directory has the sticky bit set and the file is not writable by the user, the user does not own the parent directory, the user does not own the file, and the user is not a privileged user.
The entry to be unlinked is the mount point for a mounted file system.
Thepath argument points to an illegal address.
The path argument includes non-UTF8 characters and the file system accepts only file names where all characters are part of the UTF-8 character codeset.
A signal was caught during the execution of theunlink() function.
Too many symbolic links were encountered in translatingpath.
The length of thepath argument exceedsPATH_MAX, or the length of apath component exceedsNAME_MAX while_POSIX_NO_TRUNC is in effect.
The named file does not exist or is a null pathname.
Thepath argument points to a remote machine and the link to that machine is no longer active.
A component of thepath prefix is not a directory or the provided directory descriptor forunlinkat() is notAT_FDCWD or does not reference a directory.
The named file is a directory and {PRIV_SYS_LINKDIR} is not asserted in the effective set of the calling process, or the filesystem implementation does not supportunlink() orunlinkat() on directories.
The directory entry to be unlinked is part of a read-only file system.
Theunlink() andunlinkat() functions may fail if:
Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.
The entry to be unlinked is the last directory entry to a pure procedure (shared text) file that is being executed.
Applications should usermdir(2) to remove a directory.
Seeattributes(5) for descriptions of the following attributes:
|
rm(1),close(2),link(2),open(2),rmdir(2),remove(3C),attributes(5),privileges(5),fsattr(5)
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |