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

Function mkPath

Core/MemoryFile.cpp:324–359  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322
323#ifndef MMKV_APPLE
324extern bool mkPath(const MMKVPath_t &str) {
325 char *path = strdup(str.c_str());
326
327 struct stat sb = {};
328 bool done = false;
329 char *slash = path;
330
331 while (!done) {
332 slash += strspn(slash, "/");
333 slash += strcspn(slash, "/");
334
335 done = (*slash == '\0');
336 *slash = '\0';
337
338 if (stat(path, &sb) != 0) {
339 if (errno != ENOENT || mkdir(path, 0777) != 0) {
340 MMKVWarning("%s : %s", path, strerror(errno));
341 // there's report that some Android devices might not have access permission on parent dir
342 if (done) {
343 free(path);
344 return false;
345 }
346 goto LContinue;
347 }
348 } else if (!S_ISDIR(sb.st_mode)) {
349 MMKVWarning("%s: %s", path, strerror(ENOTDIR));
350 free(path);
351 return false;
352 }
353LContinue:
354 *slash = '/';
355 }
356 free(path);
357
358 return true;
359}
360#else
361// avoid using so-called privacy API
362extern bool mkPath(const MMKVPath_t &str) {

Callers 9

initializeMMKVMethod · 0.70
getMMKVWithIDMethod · 0.70
backupOneToDirectoryMethod · 0.70
backupAllToDirectoryMethod · 0.70
encodeFilePathFunction · 0.70
getMMKVWithIDMethod · 0.70

Calls 1

statClass · 0.70

Tested by

no test coverage detected