GCC Code Coverage Report
Directory: cvmfs/ Exec Total Coverage
File: cvmfs/util/mmap_file.h Lines: 3 3 100.0 %
Date: 2019-02-03 02:48:13 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/single_copy.h"
12
13
#ifdef CVMFS_NAMESPACE_GUARD
14
namespace CVMFS_NAMESPACE_GUARD {
15
#endif
16
17
18
/**
19
 * Wraps the functionality of mmap() to create a read-only memory mapped file.
20
 *
21
 * Note: You need to call Map() to actually map the provided file path to memory
22
 */
23
class MemoryMappedFile : SingleCopy {
24
 public:
25
  explicit MemoryMappedFile(const std::string &file_path);
26
  ~MemoryMappedFile();
27
28
  bool Map();
29
  void Unmap();
30
31
907
  inline unsigned char*      buffer()    const { return mapped_file_; }
32
907
  inline size_t              size()      const { return mapped_size_; }
33
  inline const std::string&  file_path() const { return file_path_; }
34
35
910
  inline bool IsMapped() const { return mapped_; }
36
37
 private:
38
  const std::string  file_path_;
39
  int                file_descriptor_;
40
  unsigned char     *mapped_file_;
41
  size_t             mapped_size_;
42
  bool               mapped_;
43
};
44
45
46
#ifdef CVMFS_NAMESPACE_GUARD
47
}  // namespace CVMFS_NAMESPACE_GUARD
48
#endif
49
50
#endif  // CVMFS_UTIL_MMAP_FILE_H_