Kernel: add O_TRUNC

this is not supported by anything yet
This commit is contained in:
Bananymous
2023-07-10 15:48:18 +03:00
parent 2276fc95b8
commit 65fa05f998
2 changed files with 6 additions and 1 deletions

View File

@@ -49,11 +49,14 @@ namespace Kernel
BAN::ErrorOr<int> OpenFileDescriptorSet::open(BAN::StringView absolute_path, int flags)
{
if (flags & ~(O_RDONLY | O_WRONLY | O_NOFOLLOW | O_SEARCH | O_APPEND | O_CLOEXEC))
if (flags & ~(O_RDONLY | O_WRONLY | O_NOFOLLOW | O_SEARCH | O_APPEND | O_TRUNC | O_CLOEXEC))
return BAN::Error::from_errno(ENOTSUP);
auto file = TRY(VirtualFileSystem::get().file_from_absolute_path(m_credentials, absolute_path, flags));
if (flags & O_TRUNC)
TRY(file.inode->truncate(0));
int fd = TRY(get_free_fd());
m_open_files[fd] = TRY(BAN::RefPtr<OpenFileDescription>::create(file.inode, BAN::move(file.canonical_path), 0, flags));