libc: Add syscall wrappers for unlinkat() and openat()
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d9d8f7cdc7
commit
349ba0acb1
@ -16,6 +16,9 @@ extern "C"
|
||||
/* Open a file path and return a file descriptor to it. */
|
||||
int open(const char* path, int flags, ...);
|
||||
|
||||
/* Open a file path relative to a file descriptor and return a file descriptor to it. */
|
||||
int openat(int dirfd, const char* path, int flags, ...);
|
||||
|
||||
/* Create a file and return a file descriptor to it. */
|
||||
int creat(const char* path, mode_t mode);
|
||||
|
||||
|
@ -115,6 +115,9 @@ extern "C"
|
||||
/* Remove a name from the filesystem. */
|
||||
int unlink(const char* path);
|
||||
|
||||
/* Remove a name or directory from the filesystem. */
|
||||
int unlinkat(int dirfd, const char* path, int flags);
|
||||
|
||||
/* Remove a directory from the filesystem. */
|
||||
int rmdir(const char* path);
|
||||
|
||||
|
@ -19,9 +19,22 @@ extern "C"
|
||||
__errno_return(rc, int);
|
||||
}
|
||||
|
||||
int openat(int dirfd, const char* path, int flags, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, flags);
|
||||
|
||||
mode_t mode = (mode_t)va_arg(ap, int);
|
||||
|
||||
long rc = syscall(SYS_openat, dirfd, path, flags, mode);
|
||||
|
||||
va_end(ap);
|
||||
__errno_return(rc, int);
|
||||
}
|
||||
|
||||
int creat(const char* path, mode_t mode)
|
||||
{
|
||||
return open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
||||
return openat(AT_FDCWD, path, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
||||
}
|
||||
|
||||
int fcntl(int fd, int cmd, ...)
|
||||
|
@ -370,14 +370,18 @@ extern "C"
|
||||
|
||||
int unlink(const char* path)
|
||||
{
|
||||
long rc = syscall(SYS_unlinkat, AT_FDCWD, path, 0);
|
||||
return unlinkat(AT_FDCWD, path, 0);
|
||||
}
|
||||
|
||||
int unlinkat(int dirfd, const char* path, int flags)
|
||||
{
|
||||
long rc = syscall(SYS_unlinkat, dirfd, path, flags);
|
||||
__errno_return(rc, int);
|
||||
}
|
||||
|
||||
int rmdir(const char* path)
|
||||
{
|
||||
long rc = syscall(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR);
|
||||
__errno_return(rc, int);
|
||||
return unlinkat(AT_FDCWD, path, AT_REMOVEDIR);
|
||||
}
|
||||
|
||||
int gethostname(char* buf, size_t len)
|
||||
|
Loading…
Reference in New Issue
Block a user