2018-10-10 12:53:07 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-06-02 15:58:02 +03:00
|
|
|
#include "StringView.h"
|
2018-10-10 12:53:07 +03:00
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
class MappedFile {
|
|
|
|
public:
|
2019-05-28 12:53:16 +03:00
|
|
|
MappedFile() {}
|
2019-06-02 15:58:02 +03:00
|
|
|
explicit MappedFile(const StringView& file_name);
|
2018-10-10 12:53:07 +03:00
|
|
|
MappedFile(MappedFile&&);
|
|
|
|
~MappedFile();
|
|
|
|
|
2019-04-03 14:51:49 +03:00
|
|
|
MappedFile& operator=(MappedFile&&);
|
|
|
|
|
2019-01-31 19:31:23 +03:00
|
|
|
bool is_valid() const { return m_map != (void*)-1; }
|
2019-04-03 14:51:49 +03:00
|
|
|
void unmap();
|
2018-10-10 12:53:07 +03:00
|
|
|
|
|
|
|
void* pointer() { return m_map; }
|
|
|
|
const void* pointer() const { return m_map; }
|
2019-04-03 15:15:35 +03:00
|
|
|
size_t size() const { return m_size; }
|
2018-10-10 12:53:07 +03:00
|
|
|
|
|
|
|
private:
|
2019-04-03 15:15:35 +03:00
|
|
|
size_t m_size { 0 };
|
2018-10-10 12:53:07 +03:00
|
|
|
int m_fd { -1 };
|
|
|
|
void* m_map { (void*)-1 };
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
using AK::MappedFile;
|