|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
5: //
6:
1.1.1.4 root 7: //
1.1 root 8: // ファイルを mmap して提供するクラス
1.1.1.4 root 9: //
1.1 root 10:
11: #pragma once
12:
1.1.1.5 root 13: #include "nono.h"
1.1.1.2 root 14: #include "autofd.h"
1.1 root 15:
1.1.1.5 root 16: class MappedFile final
1.1 root 17: {
18: public:
1.1.1.3 root 19: // アクセスモード
20: // (enum class は字面が長くなるので手抜きしたい…)
21: using Mode = bool;
22: static const bool RW = false;
23: static const bool RdOnly = true;
24:
25: public:
1.1 root 26: MappedFile();
1.1.1.5 root 27: ~MappedFile();
1.1 root 28:
29: // ファイル名(パス名)を指定する。
30: void SetFilename(const std::string& filename);
31:
32: // エラーメッセージの表示名を変更する。
33: void SetDispname(const std::string& dispname);
34:
35: // サイズの確定しているファイルを読み書き両用でオープンして mmap する。
36: // ファイルがなければ作成する。SRAM とか用。
1.1.1.6 ! root 37: uint8 *OpenCreate(off_t len) {
! 38: return OpenCreate(len, NULL, 0);
! 39: }
! 40: uint8 *OpenCreate(off_t len, const uint8 *data, uint datalen);
1.1 root 41:
42: // クローズする (デストラクタを呼ぶだけでもよい)
43: void Close();
44:
45: // mmap されている領域の長さを返す。(ファイルサイズと同じとは限らない)
46: off_t GetMemSize() const { return memlen; }
47:
48: private:
49: // ファイルサイズをチェック
50: bool CheckFilesize() const;
51:
52: // パス名
53: std::string filename {};
54:
55: // 表示名
56: // エラー表示をほぼこちら側で行うため、
57: // ただのパス名だけでなくその場に応じたいい感じの表示にしたい。
58: std::string dispname {};
59:
1.1.1.2 root 60: autofd fd {};
1.1 root 61: uint8 *mem {};
62: off_t memlen {};
63: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.