MCPcopy Create free account
hub / github.com/cinit/TMoe / mapFilePath

Method mapFilePath

app/src/main/cpp/utils/FileMemMap.cpp:21–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19}
20
21int FileMemMap::mapFilePath(const char* path, bool readOnly, size_t length) {
22 int fd = open(path, O_RDONLY);
23 if (fd < 0) {
24 return errno;
25 }
26 if (length == 0) {
27 struct stat64 fileInfo = {};
28 if (fstat64(fd, &fileInfo) < 0) {
29 int err = errno;
30 close(fd);
31 return err;
32 }
33 length = size_t(fileInfo.st_size);
34 }
35 if (length == 0) {
36 close(fd);
37 return EINVAL;
38 }
39 size_t kPageSize = utils::GetPageSize();
40 size_t pageAlignedSize = (length + kPageSize - 1u) & ~(kPageSize - 1u);
41 void* addr = mmap(nullptr, pageAlignedSize, readOnly ? PROT_READ : (PROT_READ | PROT_WRITE), MAP_PRIVATE, fd, 0);
42 if (addr == MAP_FAILED) {
43 int err = errno;
44 close(fd);
45 return err;
46 }
47 close(fd);
48 mAddress = addr;
49 mLength = length;
50 mMapLength = pageAlignedSize;
51 return 0;
52}
53
54int FileMemMap::mapFileDescriptor(int fd, bool readOnly, size_t length, bool shared) {
55 if (fd < 0) {

Callers 1

lookupFileLogLogsEnabledFunction · 0.80

Calls 1

GetPageSizeFunction · 0.85

Tested by

no test coverage detected