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:
Sam Atkins 2023-10-06 16:13:42 +01:00 committed by Tim Schumacher
parent 89ef3ed4ce
commit 57497c6ab2
2 changed files with 10 additions and 0 deletions

View file

@ -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 };
}
}

View file

@ -280,4 +280,6 @@ char** environment();
ErrorOr<String> current_executable_path();
ErrorOr<Bytes> allocate(size_t count, size_t size);
}