banan-os/userspace/libraries/LibC/sys/stat.cpp

56 lines
1.1 KiB
C++
Raw Normal View History

#include <BAN/Assert.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <unistd.h>
2024-07-31 23:25:11 +03:00
mode_t __umask = 0;
int chmod(const char* path, mode_t mode)
{
return fchmodat(AT_FDCWD, path, mode, 0);
}
2024-08-25 15:07:42 +03:00
int fchmod(int fildes, mode_t mode)
{
return fchmodat(fildes, nullptr, mode, 0);
}
int fchmodat(int fildes, const char* path, mode_t mode, int flag)
{
return syscall(SYS_FCHMODAT, fildes, path, mode, flag);
}
2023-06-11 00:54:04 +03:00
int fstat(int fildes, struct stat* buf)
{
return fstatat(fildes, nullptr, buf, 0);
2023-06-11 00:54:04 +03:00
}
int fstatat(int fd, const char* __restrict path, struct stat* __restrict buf, int flag)
{
return syscall(SYS_FSTATAT, fd, path, buf, flag);
2023-06-11 00:54:04 +03:00
}
int lstat(const char* __restrict path, struct stat* __restrict buf)
{
return fstatat(AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW);
}
int stat(const char* __restrict path, struct stat* __restrict buf)
{
return fstatat(AT_FDCWD, path, buf, 0);
}
2024-07-31 23:25:11 +03:00
mode_t umask(mode_t cmask)
{
mode_t old = __umask;
__umask = cmask;
return old;
}
int mkdir(const char* path, mode_t mode)
{
2024-07-31 23:25:11 +03:00
return syscall(SYS_CREATE_DIR, path, __UMASKED_MODE(mode));
}