Unlinkat System Call in Linux: Unlink Files and Symbolic Links with File Descriptors
Unlinkat is a system call in Linux that unlinks a file or a symbolic link. It's similar to the unlink system call, but takes an additional argument specifying the file descriptor of the file to be unlinked. This allows unlinking the file even if it's still open by one or more processes.
The syntax for unlinkat is:
int unlinkat(int dirfd, const char *pathname, int flags);
- 'dirfd': the file descriptor of the directory containing the file to be unlinked
- 'pathname': the path of the file to be unlinked, relative to the directory specified by 'dirfd'
- 'flags': optional flags that modify the function's behavior. The most common flag is 'AT_REMOVEDIR', indicating the file to be unlinked is a directory.
If 'pathname' is a relative path, it's interpreted relative to the directory specified by 'dirfd'. If 'pathname' is an absolute path, 'dirfd' is ignored.
Unlinkat returns 0 on success and -1 on failure, with the error code set in 'errno'.
原文地址: https://www.cveoy.top/t/topic/kWvM 著作权归作者所有。请勿转载和采集!