FAT | RFS | XFS

unlink_all()

PROTOTYPE

#include <posix.h>

int unlink_all(const char *path);

DESCRIPTION

unlink_all() is a non-standard routine that removes the contents of the directory specified by path, including the contents of subdirectories. The directory itself is not deleted. The path name cannot end with “.” or “..”. Paths starting with ‘/’ are absolute. Otherwise they are relative to the CWD.

unlink_all() fails if a subdirectory is open or any task’s CWD. On TargetFAT volumes, it also fails if a regular file in the directory or a subdirectory is open. For TargetXFS and TargetRFS, it won’t fail because a regular file is open - those files are removed when closed.

The caller needs search access to the path prefix and write-access to the specified directory. The directory’s status change and data modification timestamps are updated.

If successful, unlink_all() returns 0. Otherwise, it sets errno and returns -1. Because unlink_all() returns when an error is encountered, it may have deleted some files and left others undeleted.

ERROR CODES

EACCES No execute access to a directory in the path prefix or no write access to the specified directory.
EBUSY The specified file is either open or a task’s CWD.
EFAULT path equals NULL.
ENAMETOOLONG A name in path exceeds the effective maximum file name length.
ENOENT path is the empty string or includes a directory that was not found.
ENOTDIR One of the path components is not a directory.
EROFS The volume is read-only.

EXAMPLE

  /*-------------------------------------------------------------------*/
  /* Change CWD to volume root. Delete test directory and its contents.*/
  /*-------------------------------------------------------------------*/
  if (chdir("..") || unlink_all("sort") || rmdir("sort"))
    return -1;