MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_mmap_read

Function cbm_mmap_read

src/foundation/platform.c:90–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88#include "foundation/win_utf8.h"
89
90void *cbm_mmap_read(const char *path, size_t *out_size) {
91 if (!path || !out_size) {
92 return NULL;
93 }
94 *out_size = 0;
95
96 wchar_t *wpath = cbm_path_to_wide(path);
97 if (!wpath) {
98 return NULL;
99 }
100
101 HANDLE file = CreateFileW(wpath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
102 FILE_ATTRIBUTE_NORMAL, NULL);
103 if (file == INVALID_HANDLE_VALUE) {
104 free(wpath);
105 return NULL;
106 }
107 LARGE_INTEGER sz;
108 if (!GetFileSizeEx(file, &sz) || sz.QuadPart == 0) {
109 CloseHandle(file);
110 free(wpath);
111 return NULL;
112 }
113 HANDLE mapping = CreateFileMappingW(file, NULL, PAGE_READONLY, 0, 0, NULL);
114 if (!mapping) {
115 CloseHandle(file);
116 free(wpath);
117 return NULL;
118 }
119 void *addr = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
120 CloseHandle(mapping);
121 CloseHandle(file);
122 free(wpath);
123 if (!addr) {
124 return NULL;
125 }
126 *out_size = (size_t)sz.QuadPart;
127 return addr;
128}
129
130void cbm_munmap(void *addr, size_t size) {
131 (void)size;

Callers 1

test_platform.cFile · 0.85

Calls 3

cbm_path_to_wideFunction · 0.85
openFunction · 0.70
closeFunction · 0.50

Tested by

no test coverage detected