Next: fstat, Previous: sethostname, Up: Syscalls   [Contents]


9.16 unlink ¶

#define AT_REMOVEDIR 500

int unlink(int dir_fd, const char *path, int path_len, flags);

The syscall queues for deletion the file pointed to by path. If path points to a directory, it will fail unless AT_REMOVEDIR is passed in flags, in which case it will only remove it if the directory is empty.

The syscall returns 0 or -1 on failure, with the following errno:

  • ENOENT: delete points to a file not valid for deletion.
  • ENOTEMPTY: A directory was attempted to be removed with AT_REMOVEDIR, and it was not empty.
  • EISDIR: A directory was passed for unlinking with no AT_REMOVEDIR.