1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:58:12 +00:00

LibCore: Add MappedFile::map_from_file()

This method relies on `map_from_fd_and_close()` but takes a `File`
instead of a fd.
This commit is contained in:
Lucas CHOLLET 2023-01-14 19:57:29 -05:00 committed by Sam Atkins
parent 3a95c8111d
commit 5b6e93f96a
2 changed files with 8 additions and 1 deletions

View file

@ -6,6 +6,7 @@
#include <AK/DeprecatedString.h>
#include <AK/ScopeGuard.h>
#include <LibCore/File.h>
#include <LibCore/MappedFile.h>
#include <LibCore/System.h>
#include <fcntl.h>
@ -20,6 +21,11 @@ ErrorOr<NonnullRefPtr<MappedFile>> MappedFile::map(StringView path)
return map_from_fd_and_close(fd, path);
}
ErrorOr<NonnullRefPtr<MappedFile>> MappedFile::map_from_file(NonnullOwnPtr<Core::File> stream, StringView path)
{
return map_from_fd_and_close(stream->leak_fd(Badge<MappedFile> {}), path);
}
ErrorOr<NonnullRefPtr<MappedFile>> MappedFile::map_from_fd_and_close(int fd, [[maybe_unused]] StringView path)
{
TRY(Core::System::fcntl(fd, F_SETFD, FD_CLOEXEC));