HP 3000 Manuals

unlink [ MPE/iX Developer's Kit Reference Manual Volume I ] MPE/iX 5.0 Documentation


MPE/iX Developer's Kit Reference Manual Volume I

unlink 

Removes a link from a file.

Syntax 

     #include <unistd.h>
     int unlink (const char *pathname);

Parameters 

pathname   A pointer to a string containing the pathname of a file to
           unlink (purge).  The pathname must be terminated by a null
           character.

Return Values 

0          Success.

-1         An error occurred.  The file is not unlinked, and errno is set
           to indicate the error condition.

Description 

The unlink() function removes the link name specified by pathname.  It
removes the filename pointed to by pathname from the parent directory,
then decrements the file link count.  When the link count of the file
becomes zero and no process has the file open, the file is purged from
the system and is no longer accessible.

If one or more processes have the file open when the link count becomes
zero, the file is not purged until all references to the file have been
closed.

Upon successful completion, unlink() marks for update the st_ctime and
st_mtime time fields of the parent directory.

Implementation Considerations 

Refer to the EFAULT, EIMPL, EPERM, and ESYSERR error descriptions below.

POSIX/iX does not support using unlink() on directories.  Instead, use
rmdir() to remove a directory.

POSIX/iX does not support multiple hard links to files or soft links to
files or directories.

Every file has a link count of 1 when created.  Files being unlinked
cause the link count of the file to be decremented from 1 to 0.

Errors 

If an error occurs, errno is set to one of the following values:

EACCES            CAUSE           The calling process either does not have search
                                  permission to a component of the pathname or does not
                                  have write permission to the parent directory.
                  ACTION          Make sure that the calling process has search
                                  permission for all components of the pathname and
                                  write permission to the parent directory.

EFAULT            CAUSE           The system detected a NULL or bad address in
                                  attempting to use the pathname parameter or the
                                  pathname was not terminated by a null character.
                  ACTION          Make sure that the pointer is correctly initialized.

EIMPL             CAUSE           The pathname begins with two slash characters (//).
                  ACTION          Do not begin pathnames with two slash characters
                                  (//).

ENAMETOOLONG      CAUSE           One of the following:
                                     *   The length of the pathname exceeds the
                                         {PATH_MAX} limit (defined in the file
                                         <limits.h>).
                                     *   A component of the pathname is longer than
                                         {NAME_MAX} (defined in <limits.h>), and
                                         {_POSIX_NO_TRUNC} is in effect for that
                                         directory.
                  ACTION          Make sure that both the component's length and the
                                  full pathname length do not exceed the {NAME_MAX} or
                                  {PATH_MAX} limits.

          Table 4-0.  (cont.) 

ENOENT            CAUSE           The specified file does not exist, or pathname points
                                  to an empty string.
                  ACTION          Specify a valid pathname.

ENOTDIR           CAUSE           A component of the pathname is not a directory.
                  ACTION          Specify a valid pathname.

EPERM             CAUSE           The specified file is a directory.
                  ACTION          Do not attempt to unlink a directory.  Use rmdir()
                                  instead.

ESYSERR           CAUSE           An operating system error has occurred that does not
                                  map directly to any of the above errors.
                  ACTION          Examine the MPE/iX error stack for the type of system
                                  error.

See Also 

close(), open(), rmdir(), POSIX.1 (Section 5.5.1)



MPE/iX 5.0 Documentation