summaryrefslogtreecommitdiff
path: root/AK/MappedFile.h
blob: 4fbc1872dd39c3ab4e162b713120304a5f511d99 (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&& fileName);
    MappedFile(MappedFile&&);
    ~MappedFile();

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

    void* pointer() { return m_map; }
    const void* pointer() const { return m_map; }
    size_t fileLength() const { return m_fileLength; }

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

}

using AK::MappedFile;