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

AK: Make MappedFile store why it is invalid

This makes AK::MappedFile save the errno either open() or mmap() failed
with.
This commit is contained in:
AnotherTest 2020-07-22 19:49:47 +04:30 committed by Andreas Kling
parent d04c833002
commit 6131417904
2 changed files with 12 additions and 2 deletions

View file

@ -41,6 +41,7 @@ MappedFile::MappedFile(const StringView& file_name)
int fd = open_with_path_length(file_name.characters_without_null_termination(), file_name.length(), O_RDONLY | O_CLOEXEC, 0);
if (fd == -1) {
m_errno = errno;
perror("open");
return;
}
@ -50,8 +51,10 @@ MappedFile::MappedFile(const StringView& file_name)
m_size = st.st_size;
m_map = mmap(nullptr, m_size, PROT_READ, MAP_SHARED, fd, 0);
if (m_map == MAP_FAILED)
if (m_map == MAP_FAILED) {
m_errno = errno;
perror("mmap");
}
#ifdef DEBUG_MAPPED_FILE
dbgprintf("MappedFile{%s} := { fd=%d, m_size=%u, m_map=%p }\n", file_name.characters(), fd, m_size, m_map);