unlink()

removes link to file 

Function


SYNOPSIS

#include <unistd.h>

int unlink(const char *pathname);


DESCRIPTION

The unlink() function removes a link to a file, and decrements the link count of the referenced file by one. When the file's link count becomes 0 and no process has the file open, the space occupied by the file is freed, and the file is no longer accessible. If one or more processes have the file open when the last link is removed, the link is removed before unlink() returns, but the removal of the file contents is postponed until all references to the file are closed.

Upon successful completion, unlink() will mark for update the st_ctime field of the file if its link count is not 0.


PARAMETERS

pathname 

Points to the path name that names the file to be unlinked.


RETURN VALUES

If successful, the unlink() function returns a value of zero. On failure, unlink() returns -1 and sets errno to one of the following:

EACCES 

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

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

EBUSY 

The directory entry to be unlinked is in use by the system or another process and the file could not be moved to a hidden area.

EFAULT 

pathname is an invalid pointer.

ENAMETOOLONG 

The length of the pathname parameter exceeds PATH_MAX or a path name component is longer than NAME_MAX.

ENOENT 

The named file does not exist or pathname points to an empty string or a component of the pathname prefix is not a directory.

EPERM 

The file named by pathname is a directory.

EROFS 

The directory entry to be unlinked is part of a read-only file system.

ETXTBSY 

The directory entry to be unlinked is in use.


CONFORMANCE

POSIX.1 (1996), with exceptions.


MULTITHREAD SAFETY LEVEL

Async-signal-safe.


PORTING ISSUES

Because of limitations on Windows, if one or more processes have the file open when the last link is removed, and if the file can be moved, the NuTCRACKER Platform moves the file to a hidden area on the drive, so that the directory entry is deleted. The file moved to the hidden area resides there until the last handle to that file is closed.

The unlink() does not work properly with UNC file names.

File names are treated as multibyte sequences and are converted to Unicode (UTF-16) before passing to Win32. The conversion is either performed based on the current thread locale, set using uselocale() or the process locale as set by a call to setlocale(), and overridden by _NutConf() _NC_SET_ANSI_LOCALE and _NC_SET_UTF8_LOCALE options. Under all other conditions, the multibyte sequences are considered to be from the ANSI code page for the current windows system locale.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
close(), link(), open(), rename(), rmdir()


PTC MKS Toolkit 10.2 Documentation Build 28.