summaryrefslogtreecommitdiff
path: root/AK/MappedFile.h
blob: 5eee9ed93981fd2d2e46981c397d4c2537a2d71b (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
#pragma once

#include "AKString.h"

namespace AK {

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

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

    void* pointer() { return m_map; }
    const void* pointer() const { return m_map; }
    size_t file_length() const { return m_file_length; }

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

}

using AK::MappedFile;