mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
AK: Add method to create MappedFile from fd
This commit is contained in:
parent
95ee7069d5
commit
bc75ca4fe5
Notes:
sideshowbarker
2024-07-18 07:19:36 +09:00
Author: https://github.com/timmot Commit: https://github.com/SerenityOS/serenity/commit/bc75ca4fe55 Pull-request: https://github.com/SerenityOS/serenity/pull/9229
2 changed files with 10 additions and 0 deletions
|
@ -21,6 +21,15 @@ Result<NonnullRefPtr<MappedFile>, OSError> MappedFile::map(const String& path)
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return OSError(errno);
|
return OSError(errno);
|
||||||
|
|
||||||
|
return map_from_fd_and_close(fd, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result<NonnullRefPtr<MappedFile>, OSError> MappedFile::map_from_fd_and_close(int fd, [[maybe_unused]] String const& path)
|
||||||
|
{
|
||||||
|
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
|
||||||
|
return OSError(errno);
|
||||||
|
}
|
||||||
|
|
||||||
ScopeGuard fd_close_guard = [fd] {
|
ScopeGuard fd_close_guard = [fd] {
|
||||||
close(fd);
|
close(fd);
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,6 +20,7 @@ class MappedFile : public RefCounted<MappedFile> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Result<NonnullRefPtr<MappedFile>, OSError> map(const String& path);
|
static Result<NonnullRefPtr<MappedFile>, OSError> map(const String& path);
|
||||||
|
static Result<NonnullRefPtr<MappedFile>, OSError> map_from_fd_and_close(int fd, String const& path);
|
||||||
~MappedFile();
|
~MappedFile();
|
||||||
|
|
||||||
void* data() { return m_data; }
|
void* data() { return m_data; }
|
||||||
|
|
Loading…
Reference in a new issue