close_unlink()
PROTOTYPE
#include <posix.h>
int close_unlink(int fid);
DESCRIPTION
close_unlink() frees the file control block specified by file descriptor fid and unlinks the associated file. After it returns, the value of fid no longer references the file.
For directories, close_unlink() fails with errno set to ENOTEMPTY if the directory is not empty. It fails with errno set to EBUSY if the directory is open, a root directory, or any task’s CWD.
TargetFAT open regular files cannot be removed, the call fails with errno set to EBUSY. For TargetRFS and TargetXFS, the file’s link count is decremented and the call succeeds. The file is deleted if its link count reaches zero. If the file is open, removal is delayed until the last open handle is closed. If a reset occurs, files with a link count of zero are deleted during mount().
The caller needs write-access to the parent directory. The parent directory’s status change and data modification timestamps and-if not deleted-the file’s status change timestamp are updated.
If successful, close_unlink() returns 0. Otherwise, it sets errno and returns -1.
ERROR CODES
| EACCES | No write access to the parent directory. |
| EBADF | fid is not the descriptor of an open file. |
| EBUSY | The specified file is either open, a root directory, or a task’s CWD. |
| EROFS | The volume is read-only. |
EXAMPLE
/*---------------------------------------------------------------*/
/* Close file and unlink the path opened as fid. */
/*---------------------------------------------------------------*/
if (close_unlink(fid))
perror("error closing/unlinking file");