mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 22:35:07 +00:00
Kernel: Make KBuffer::try_create_with_size() return KResultOr
This allows us to use TRY() in a lot of new places.
This commit is contained in:
parent
c69035c630
commit
899cee8185
10 changed files with 31 additions and 72 deletions
|
@ -169,9 +169,7 @@ KResultOr<size_t> TmpFSInode::write_bytes(off_t offset, size_t size, const UserO
|
|||
// FIXME: Fix this so that no memcpy() is necessary, and we can just grow the
|
||||
// KBuffer and it will add physical pages as needed while keeping the
|
||||
// existing ones.
|
||||
auto tmp = KBuffer::try_create_with_size(new_size * 2);
|
||||
if (!tmp)
|
||||
return ENOMEM;
|
||||
auto tmp = TRY(KBuffer::try_create_with_size(new_size * 2));
|
||||
tmp->set_size(new_size);
|
||||
if (m_content)
|
||||
memcpy(tmp->data(), m_content->data(), old_size);
|
||||
|
@ -316,9 +314,7 @@ KResult TmpFSInode::truncate(u64 size)
|
|||
if (size == 0)
|
||||
m_content.clear();
|
||||
else if (!m_content) {
|
||||
m_content = KBuffer::try_create_with_size(size);
|
||||
if (!m_content)
|
||||
return ENOMEM;
|
||||
m_content = TRY(KBuffer::try_create_with_size(size));
|
||||
} else if (static_cast<size_t>(size) < m_content->capacity()) {
|
||||
size_t prev_size = m_metadata.size;
|
||||
m_content->set_size(size);
|
||||
|
@ -326,9 +322,7 @@ KResult TmpFSInode::truncate(u64 size)
|
|||
memset(m_content->data() + prev_size, 0, size - prev_size);
|
||||
} else {
|
||||
size_t prev_size = m_metadata.size;
|
||||
auto tmp = KBuffer::try_create_with_size(size);
|
||||
if (!tmp)
|
||||
return ENOMEM;
|
||||
auto tmp = TRY(KBuffer::try_create_with_size(size));
|
||||
memcpy(tmp->data(), m_content->data(), prev_size);
|
||||
m_content = move(tmp);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue