MCPcopy Create free account
hub / github.com/Tencent/MMKV / mkPath

Function mkPath

Core/MemoryFile_Win32.cpp:324–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322}
323
324bool mkPath(const MMKVPath_t &str) {
325 wchar_t *path = _wcsdup(str.c_str());
326
327 bool done = false;
328 wchar_t *slash = path;
329
330 while (!done) {
331 slash += wcsspn(slash, L"\\");
332 slash += wcscspn(slash, L"\\");
333
334 done = (*slash == L'\0');
335 *slash = L'\0';
336
337 auto attribute = GetFileAttributes(path);
338 if (attribute == INVALID_FILE_ATTRIBUTES) {
339 if (!CreateDirectory(path, nullptr)) {
340 const auto &utf8Path = MMKVPath_t2String(str);
341 MMKVError("fail to create dir:%s, %d", utf8Path.c_str(), GetLastError());
342 free(path);
343 return false;
344 }
345 } else if (!(attribute & FILE_ATTRIBUTE_DIRECTORY)) {
346 const auto &utf8Path = MMKVPath_t2String(str);
347 MMKVError("%s attribute:%d not a directory", utf8Path.c_str(), attribute);
348 free(path);
349 return false;
350 }
351
352 *slash = L'\\';
353 }
354 free(path);
355 return true;
356}
357
358MMBuffer *readWholeFile(const MMKVPath_t &nsFilePath) {
359 MMBuffer *buffer = nullptr;

Callers

nothing calls this directly

Calls 1

MMKVPath_t2StringFunction · 0.85

Tested by

no test coverage detected