FAT | RFS | XFS

remove()

PROTOTYPE

#include <stdio.h>

int remove(const char *path);

DESCRIPTION

remove() unlinks the file specified by path. This path name cannot end with “.” or “..”. Paths starting with ‘/’ are absolute. Otherwise they are relative to the CWD.

remove() fails with errno set to ENOTEMPTY if used on a non-empty directory. It fails with errno set to EBUSY if the directory is either 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 and execute-access to every directory in the path prefix. The parent directory’s status change and data modification timestamps and-if not deleted-the file’s status change timestamp are updated.

If successful, remove() returns 0. Otherwise, it sets errno and returns -1.

ERROR CODES

EACCES No search access to path prefix or write access to parent directory.
EBUSY The specified file is either open, a root directory, or a task’s CWD.
EFAULT path equals NULL.
EINVAL path ends with “.” or “..”.
ENAMETOOLONG A name in path exceeds the effective maximum file name length.
ENOENT path is the empty string or includes a file that was not found.
ENOTDIR One of the non-leaf path components is not a directory.
ENOTEMPTY The directory specified by path is not empty.
EROFS The volume is read-only.

EXAMPLE

if (remove(path1))
  perror("remove() failed");