Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
File_Slice.h
Go to the documentation of this file.
1#ifndef joedb_File_Slice_declared
2#define joedb_File_Slice_declared
3
6
7#include <sys/mman.h>
8
9namespace joedb
10{
11 /// @ingroup journal
13 {
14 private:
15 const size_t mapped_size;
16
17 public:
18 File_Slice(int fd, size_t offset, size_t size):
20 (
21 (char *)mmap
22 (
23 nullptr,
24 offset + size,
27 fd,
28 0
29 ) + offset,
30 size
31 ),
32 mapped_size(offset + size)
33 {
34 if (data - offset == MAP_FAILED)
35 Posix_File::throw_last_error("mapping", "file");
36 }
37
38 File_Slice(const File_Slice &) = delete;
39 File_Slice &operator=(const File_Slice &) = delete;
40
42 {
43 munmap(const_cast<void *>(static_cast<const void *>(data)), mapped_size);
44 }
45 };
46}
47
48#endif
File_Slice & operator=(const File_Slice &)=delete
File_Slice(int fd, size_t offset, size_t size)
Definition File_Slice.h:18
File_Slice(const File_Slice &)=delete
static void throw_last_error(const char *action, const char *file_name)
Definition Blob.h:7