gtpc2m98 | C/C++ Language Support User's Guide |
This function removes a directory entry.
Format
#include <unistd.h> int unlink(const char *pathname);
The unlink function deletes the link named by pathname and decrements the link count for the file itself.
pathname can refer to a path name, a link, or a symbolic link. If pathname refers to a symbolic link, the unlink function removes the symbolic link, but not any file or directory named by the contents of the symbolic link.
If any processes have the file open when the unlink function removes the last link and the directory entry, the file itself remains available to these processes until they close it. The last process to be completed closes the file.
The unlink function cannot be used to remove a directory; use the rmdir function instead.
TPF deviation from POSIX |
---|
The TPF system does not support the ctime (change time) time stamp. |
Normal Return
If successful, the unlink function updates the modification time for the parent directory and returns a value of 0.
Error Return
If unsuccessful, the unlink function returns a value of -1 and sets errno to one of the following:
Programming Considerations
The TPF system does not support creating, updating, or deleting files in 1052 or UTIL state. Special files may or may not be writable in 1052 or UTIL state depending on the device driver implementation.
Examples
The following example removes a directory entry.
#include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <stdio.h> main() { int fd; char fn[]="unlink.file"; if ((fd = creat(fn, S_IWUSR)) < 0) perror("creat() error"); else { close(fd); if (unlink(fn) != 0) perror("unlink() error"); } }
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.