COHERENT manpages
This page displays the COHERENT manpage for unlink() [Remove a file].
List of available manpages
Index
unlink() -- System Call (libc) Remove a file #include <unistd.h> int unlink(name) char *name; unlink() removes the directory entry for the given file name, which in effect erases name from the disk. name cannot be opened once it has been unlink()'d. If name is the last link, unlink() frees the i-node and data blocks. Deallocation is delayed if the file is open. Other links to the file remain intact. Example This example removes the files named on the command line. #include <unistd.h> main(argc, argv) int argc; char *argv[]; { int i; for (i = 1; i < argc; i++) { if (unlink(argv[i]) == -1) { printf("Cannot unlink \"%s\"\n", argv[i]); exit(EXIT_FAILURE); } } exit(EXIT_SUCCESS); } See Also libc, link(), ln, remove(), rm, rmdir, unistd.h POSIX Standard, §5.5.1 Diagnostics unlink() returns zero when successful. It returns -1 if file does not exist, if the user does not have write and search permission in the directory containing file, or if file is a directory and the invoker is not the superuser.