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

Function cbm_module_path_utf8

src/foundation/win_utf8.h:166–193  ·  view source on GitHub ↗

Resolve the running image without passing through the active ANSI code page. * The returned UTF-8 string is heap allocated. Grow dynamically so an * extended-length install path is never mistaken for a complete path. */

Source from the content-addressed store, hash-verified

164 * The returned UTF-8 string is heap allocated. Grow dynamically so an
165 * extended-length install path is never mistaken for a complete path. */
166static inline char *cbm_module_path_utf8(void) {
167 DWORD capacity = 512U;
168 while (capacity <= 32768U) {
169 wchar_t *wide = (wchar_t *)calloc((size_t)capacity, sizeof(*wide));
170 if (!wide) {
171 return NULL;
172 }
173 SetLastError(ERROR_SUCCESS);
174 DWORD length = GetModuleFileNameW(NULL, wide, capacity);
175 if (length > 0U && length < capacity) {
176 cbm_module_path_unprefix(wide);
177 char *utf8 = cbm_wide_to_utf8(wide);
178 free(wide);
179 return utf8;
180 }
181 DWORD error = GetLastError();
182 free(wide);
183 if (length == 0U || (length < capacity && error != ERROR_INSUFFICIENT_BUFFER) ||
184 capacity == 32768U) {
185 return NULL;
186 }
187 capacity *= 2U;
188 if (capacity > 32768U) {
189 capacity = 32768U;
190 }
191 }
192 return NULL;
193}
194
195#endif /* _WIN32 */
196#endif /* CBM_WIN_UTF8_H */

Callers 2

cbm_detect_self_pathFunction · 0.85
resolve_self_executableFunction · 0.85

Calls 2

cbm_module_path_unprefixFunction · 0.85
cbm_wide_to_utf8Function · 0.85

Tested by

no test coverage detected