GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/util/mmap_file.h
Date: 2024-04-21 02:33:16
Exec Total Coverage
Lines: 2 2 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #ifndef CVMFS_UTIL_MMAP_FILE_H_
6 #define CVMFS_UTIL_MMAP_FILE_H_
7
8 #include <cstddef>
9 #include <string>
10
11 #include "util/export.h"
12 #include "util/single_copy.h"
13
14 #ifdef CVMFS_NAMESPACE_GUARD
15 namespace CVMFS_NAMESPACE_GUARD {
16 #endif
17
18
19 /**
20 * Wraps the functionality of mmap() to create a read-only memory mapped file.
21 *
22 * Note: You need to call Map() to actually map the provided file path to memory
23 */
24 class CVMFS_EXPORT MemoryMappedFile : SingleCopy {
25 public:
26 explicit MemoryMappedFile(const std::string &file_path);
27 ~MemoryMappedFile();
28
29 bool Map();
30 void Unmap();
31
32 15689 inline unsigned char* buffer() const { return mapped_file_; }
33 inline size_t size() const { return mapped_size_; }
34 inline const std::string& file_path() const { return file_path_; }
35
36 258 inline bool IsMapped() const { return mapped_; }
37
38 private:
39 const std::string file_path_;
40 int file_descriptor_;
41 unsigned char *mapped_file_;
42 size_t mapped_size_;
43 bool mapped_;
44 };
45
46
47 #ifdef CVMFS_NAMESPACE_GUARD
48 } // namespace CVMFS_NAMESPACE_GUARD
49 #endif
50
51 #endif // CVMFS_UTIL_MMAP_FILE_H_
52