mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
LibCore: Add a Core::System wrapper for memory allocation
Allocating raw memory isn't something we do often, but it does happen. Let's make it comfier.
This commit is contained in:
parent
89ef3ed4ce
commit
57497c6ab2
Notes:
sideshowbarker
2024-07-17 01:53:23 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/57497c6ab2 Pull-request: https://github.com/SerenityOS/serenity/pull/21298 Reviewed-by: https://github.com/timschumi ✅
2 changed files with 10 additions and 0 deletions
|
@ -1837,4 +1837,12 @@ ErrorOr<String> current_executable_path()
|
|||
return String::from_utf8({ path, strlen(path) });
|
||||
}
|
||||
|
||||
ErrorOr<Bytes> allocate(size_t count, size_t size)
|
||||
{
|
||||
auto* data = static_cast<u8*>(calloc(count, size));
|
||||
if (!data)
|
||||
return Error::from_errno(errno);
|
||||
return Bytes { data, size * count };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -280,4 +280,6 @@ char** environment();
|
|||
|
||||
ErrorOr<String> current_executable_path();
|
||||
|
||||
ErrorOr<Bytes> allocate(size_t count, size_t size);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue