Mono.Unix.Native.Syscall.unlink Method
Deletes a link to a file.

Syntax

public static int unlink (string pathname)

See Also

Syscall.chflags
Syscall.close
Syscall.link
Syscall.rmdir

Parameters

pathname
A string containing the directory entry to delete.

Returns

On success, zero is returned. On error, -1 is returned and Stdlib.GetLastError returns the translated error.

Usage

The unlink() succeeds unless:

Error Details
Errno.ENOTDIR

A component of the path prefix is not a directory.

Errno.ENAMETOOLONG

A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters.

Errno.ENOENT

The named file does not exist.

Errno.EACCES

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

Errno.EACCES

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

Errno.ELOOP

Too many symbolic links were encountered in translating the pathname.

Errno.EPERM

The named file is a directory.

Errno.EPERM

The named file has its immutable or append-only flag set, see the Syscall.chflags(2) manual page for more information.

Errno.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.

Errno.EBUSY

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

Errno.EIO

An I/O error occurred while deleting the directory entry or deallocating the inode.

Errno.EROFS

The named file resides on a read-only file system.

Errno.EFAULT

The path argument points outside the process's allocated address space.

Remarks

If the file is not used and it was the last link, the file is also deleted.

The unlink() system call removes the link named by pathname 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 process 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. The path argument may not be a directory.

Requirements

Namespace: Mono.Unix.Native
Assembly: Mono.Posix (in Mono.Posix.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0