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:223–250  ·  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

221 * The returned UTF-8 string is heap allocated. Grow dynamically so an
222 * extended-length install path is never mistaken for a complete path. */
223static inline char *cbm_module_path_utf8(void) {
224 DWORD capacity = 512U;
225 while (capacity <= 32768U) {
226 wchar_t *wide = (wchar_t *)calloc((size_t)capacity, sizeof(*wide));
227 if (!wide) {
228 return NULL;
229 }
230 SetLastError(ERROR_SUCCESS);
231 DWORD length = GetModuleFileNameW(NULL, wide, capacity);
232 if (length > 0U && length < capacity) {
233 cbm_module_path_unprefix(wide);
234 char *utf8 = cbm_wide_to_utf8(wide);
235 free(wide);
236 return utf8;
237 }
238 DWORD error = GetLastError();
239 free(wide);
240 if (length == 0U || (length < capacity && error != ERROR_INSUFFICIENT_BUFFER) ||
241 capacity == 32768U) {
242 return NULL;
243 }
244 capacity *= 2U;
245 if (capacity > 32768U) {
246 capacity = 32768U;
247 }
248 }
249 return NULL;
250}
251
252#endif /* _WIN32 */
253#endif /* CBM_WIN_UTF8_H */

Callers 4

cbm_detect_self_pathFunction · 0.85
resolve_self_executableFunction · 0.85
tf_runner_imageFunction · 0.85
test_subprocess.cFile · 0.85

Calls 2

cbm_module_path_unprefixFunction · 0.85
cbm_wide_to_utf8Function · 0.85

Tested by 1

tf_runner_imageFunction · 0.68