IO: optimize createSubfolders (#1382)

This commit is contained in:
apocelipes
2024-11-10 08:27:34 +08:00
committed by GitHub
parent 837903e845
commit 0284e4ccc4
2 changed files with 10 additions and 7 deletions
+5 -4
View File
@@ -23,13 +23,14 @@
static void createSubfolders(const char* fileName)
{
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
char path[PATH_MAX];
char *token = NULL;
char *pathTail = path;
while((token = strchr(fileName, '/')) != NULL)
{
ffStrbufAppendNS(&path, (uint32_t)(token - fileName + 1), fileName);
mkdir(path.chars, S_IRWXU | S_IRGRP | S_IROTH);
uint32_t length = (uint32_t)(token - fileName + 1);
pathTail = ffStrCopyN(pathTail, fileName, length);
mkdir(path, S_IRWXU | S_IRGRP | S_IROTH);
fileName = token + 1;
}
}
+5 -3
View File
@@ -8,12 +8,14 @@
static void createSubfolders(const char* fileName)
{
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
char path[MAX_PATH];
char *token = NULL;
char *pathTail = path;
while((token = strchr(fileName, '/')) != NULL)
{
ffStrbufAppendNS(&path, (uint32_t)(token - fileName + 1), fileName);
CreateDirectoryA(path.chars, NULL);
uint32_t length = (uint32_t)(token - fileName + 1);
pathTail = ffStrCopyN(pathTail, fileName, length);
CreateDirectoryA(path, NULL);
fileName = token + 1;
}
}