1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:28:11 +00:00

LibCore: Add option to Stream::File to not close the file on destruction

This commit is contained in:
davidot 2022-10-12 11:31:34 +02:00 committed by Andrew Kaster
parent 279121fa10
commit e0cccaa583
2 changed files with 16 additions and 5 deletions

View file

@ -127,7 +127,7 @@ ErrorOr<NonnullOwnPtr<File>> File::open(StringView filename, OpenMode mode, mode
return file;
}
ErrorOr<NonnullOwnPtr<File>> File::adopt_fd(int fd, OpenMode mode)
ErrorOr<NonnullOwnPtr<File>> File::adopt_fd(int fd, OpenMode mode, ShouldCloseFileDescriptor should_close_file_descriptor)
{
if (fd < 0) {
return Error::from_errno(EBADF);
@ -138,7 +138,7 @@ ErrorOr<NonnullOwnPtr<File>> File::adopt_fd(int fd, OpenMode mode)
return Error::from_errno(EINVAL);
}
auto file = TRY(adopt_nonnull_own_or_enomem(new (nothrow) File(mode)));
auto file = TRY(adopt_nonnull_own_or_enomem(new (nothrow) File(mode, should_close_file_descriptor)));
file->m_fd = fd;
return file;
}