mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 14:17:42 +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:
parent
3a95c8111d
commit
5b6e93f96a
2 changed files with 8 additions and 1 deletions
|
@ -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));
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <AK/Noncopyable.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/Result.h>
|
||||
#include <LibCore/Forward.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
|
@ -20,6 +20,7 @@ class MappedFile : public RefCounted<MappedFile> {
|
|||
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<MappedFile>> map(StringView path);
|
||||
static ErrorOr<NonnullRefPtr<MappedFile>> map_from_file(NonnullOwnPtr<Core::File>, StringView path);
|
||||
static ErrorOr<NonnullRefPtr<MappedFile>> map_from_fd_and_close(int fd, StringView path);
|
||||
~MappedFile();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue