summaryrefslogtreecommitdiff
path: root/AK/MappedFile.h
blob: 0398bff7bdbb83090b17a39a2d897e25c3df48b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once

#include "AKString.h"

namespace AK {

class MappedFile {
public:
    MappedFile() { }
    explicit MappedFile(const String& file_name);
    MappedFile(MappedFile&&);
    ~MappedFile();

    MappedFile& operator=(MappedFile&&);

    bool is_valid() const { return m_map != (void*)-1; }
    void unmap();

    void* pointer() { return m_map; }
    const void* pointer() const { return m_map; }
    size_t size() const { return m_size; }

private:
    String m_file_name;
    size_t m_size { 0 };
    int m_fd { -1 };
    void* m_map { (void*)-1 };
};

}

using AK::MappedFile;