mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 06:02:07 +03:00
Kernel: Add KBuffer::bytes() and use it
(Instead of hand-wrapping { data(), size() } in a bunch of places.)
This commit is contained in:
parent
bee2de4b31
commit
524ef5e475
Notes:
sideshowbarker
2024-07-18 04:25:47 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/524ef5e4759
@ -75,8 +75,7 @@ KResultOr<NonnullRefPtr<Custody>> Inode::resolve_as_link(Custody& base, RefPtr<C
|
|||||||
// contents as a path and resolves that. That is, it
|
// contents as a path and resolves that. That is, it
|
||||||
// behaves exactly how you would expect a symlink to work.
|
// behaves exactly how you would expect a symlink to work.
|
||||||
auto contents = TRY(read_entire());
|
auto contents = TRY(read_entire());
|
||||||
auto path = StringView(contents->data(), contents->size());
|
return VirtualFileSystem::the().resolve_path(StringView { contents->bytes() }, base, out_parent, options, symlink_recursion_level);
|
||||||
return VirtualFileSystem::the().resolve_path(path, base, out_parent, options, symlink_recursion_level);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Inode::Inode(FileSystem& fs, InodeIndex index)
|
Inode::Inode(FileSystem& fs, InodeIndex index)
|
||||||
|
@ -333,7 +333,7 @@ Plan9FS::Message::Message(Plan9FS& fs, Type type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Plan9FS::Message::Message(NonnullOwnPtr<KBuffer>&& buffer)
|
Plan9FS::Message::Message(NonnullOwnPtr<KBuffer>&& buffer)
|
||||||
: m_built { move(buffer), Decoder({ buffer->data(), buffer->size() }) }
|
: m_built { move(buffer), Decoder({ buffer->bytes() }) }
|
||||||
, m_have_been_built(true)
|
, m_have_been_built(true)
|
||||||
{
|
{
|
||||||
u32 size;
|
u32 size;
|
||||||
|
@ -42,6 +42,9 @@ public:
|
|||||||
[[nodiscard]] size_t size() const { return m_size; }
|
[[nodiscard]] size_t size() const { return m_size; }
|
||||||
[[nodiscard]] size_t capacity() const { return m_region->size(); }
|
[[nodiscard]] size_t capacity() const { return m_region->size(); }
|
||||||
|
|
||||||
|
[[nodiscard]] ReadonlyBytes bytes() const { return { data(), size() }; }
|
||||||
|
[[nodiscard]] Bytes bytes() { return { data(), size() }; }
|
||||||
|
|
||||||
void set_size(size_t size)
|
void set_size(size_t size)
|
||||||
{
|
{
|
||||||
VERIFY(size <= capacity());
|
VERIFY(size <= capacity());
|
||||||
|
@ -48,7 +48,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (!m_buffer)
|
if (!m_buffer)
|
||||||
return {};
|
return {};
|
||||||
return ReadonlyBytes { m_buffer->data(), m_buffer->size() };
|
return m_buffer->bytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -372,7 +372,7 @@ KResultOr<size_t> IPv4Socket::receive_packet_buffered(OpenFileDescription& descr
|
|||||||
return bytes_written;
|
return bytes_written;
|
||||||
}
|
}
|
||||||
|
|
||||||
return protocol_receive(ReadonlyBytes { packet->data->data(), packet->data->size() }, buffer, buffer_length, flags);
|
return protocol_receive(packet->data->bytes(), buffer, buffer_length, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
KResultOr<size_t> IPv4Socket::recvfrom(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> user_addr, Userspace<socklen_t*> user_addr_length, Time& packet_timestamp)
|
KResultOr<size_t> IPv4Socket::recvfrom(OpenFileDescription& description, UserOrKernelBuffer& buffer, size_t buffer_length, int flags, Userspace<sockaddr*> user_addr, Userspace<socklen_t*> user_addr_length, Time& packet_timestamp)
|
||||||
|
@ -34,7 +34,7 @@ struct PacketWithTimestamp : public RefCounted<PacketWithTimestamp> {
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadonlyBytes bytes() { return { buffer->data(), buffer->size() }; };
|
ReadonlyBytes bytes() { return buffer->bytes(); }
|
||||||
|
|
||||||
NonnullOwnPtr<KBuffer> buffer;
|
NonnullOwnPtr<KBuffer> buffer;
|
||||||
Time timestamp;
|
Time timestamp;
|
||||||
|
@ -27,7 +27,7 @@ KResultOr<FlatPtr> Process::sys$module_load(Userspace<const char*> user_path, si
|
|||||||
auto description = TRY(VirtualFileSystem::the().open(path->view(), O_RDONLY, 0, current_directory()));
|
auto description = TRY(VirtualFileSystem::the().open(path->view(), O_RDONLY, 0, current_directory()));
|
||||||
auto payload = TRY(description->read_entire_file());
|
auto payload = TRY(description->read_entire_file());
|
||||||
|
|
||||||
auto storage = TRY(KBuffer::try_create_with_bytes(ReadonlyBytes { payload->data(), payload->size() }));
|
auto storage = TRY(KBuffer::try_create_with_bytes(payload->bytes()));
|
||||||
|
|
||||||
auto elf_image = try_make<ELF::Image>(storage->data(), storage->size());
|
auto elf_image = try_make<ELF::Image>(storage->data(), storage->size());
|
||||||
if (!elf_image)
|
if (!elf_image)
|
||||||
|
Loading…
Reference in New Issue
Block a user