unlink -- Delete File

Format

#include <stdio.h>  /* also in <io.h> */
int unlink(const char *pathname);

Language Level: XPG4, Extension
unlink deletes the file specified by pathname.

Portability Note: For portability, use the ANSI/ISO function remove instead of unlink.

Note: In earlier releases of the C/C++ run-time library, unlink began with an underscore (_unlink). Because it is defined by the X/Open standard, the underscore has been removed. For compatibility, IBM C and C++ Compilers will map _unlink to unlink for you.

Return Value
unlink returns 0 if the file is successfully deleted. A return value of -1 indicates an error, and errno is set to one of the following values:

Value Meaning
EACCESS The path name specifies a read-only file or a directory.
EISOPEN The file is open.
ENOENT An incorrect path name was specified, or the file or path name was not found.

Example
This example deletes the file tmpfile from the system or prints an error message if unable to delete it.

#include <stdio.h>
int main(void)
{
   if (-1 == unlink("tmpfile"))
      perror("Cannot delete tmpfile");
   else
      printf("tmpfile has been successfully deleted\n");
   return 0;
   /*******************************************************
      If the file "tmpfile" exists, the output should be:
      tmpfile has been successfully deleted
   *******************************************************/
}


remove -- Delete File
_rmtmp -- Remove Temporary Files
<stdio.h>