From 9314050df935b678ea3b055af8961069edfbe8d4 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 11 Nov 2024 17:32:47 +0800 Subject: [PATCH] Revert "IO: optimize createSubfolders (#1382)" This reverts commit 0284e4ccc4a9b133b045a4c20cb7eb13e77f2441. --- src/common/io/io_unix.c | 9 ++++----- src/common/io/io_windows.c | 8 +++----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/common/io/io_unix.c b/src/common/io/io_unix.c index d66354481b..4cb946d0e8 100644 --- a/src/common/io/io_unix.c +++ b/src/common/io/io_unix.c @@ -23,14 +23,13 @@ static void createSubfolders(const char* fileName) { - char path[PATH_MAX]; + FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); + char *token = NULL; - char *pathTail = path; while((token = strchr(fileName, '/')) != NULL) { - uint32_t length = (uint32_t)(token - fileName + 1); - pathTail = ffStrCopyN(pathTail, fileName, length); - mkdir(path, S_IRWXU | S_IRGRP | S_IROTH); + ffStrbufAppendNS(&path, (uint32_t)(token - fileName + 1), fileName); + mkdir(path.chars, S_IRWXU | S_IRGRP | S_IROTH); fileName = token + 1; } } diff --git a/src/common/io/io_windows.c b/src/common/io/io_windows.c index 90f12b76a6..9f1a96ce53 100644 --- a/src/common/io/io_windows.c +++ b/src/common/io/io_windows.c @@ -8,14 +8,12 @@ static void createSubfolders(const char* fileName) { - char path[MAX_PATH]; + FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); char *token = NULL; - char *pathTail = path; while((token = strchr(fileName, '/')) != NULL) { - uint32_t length = (uint32_t)(token - fileName + 1); - pathTail = ffStrCopyN(pathTail, fileName, length); - CreateDirectoryA(path, NULL); + ffStrbufAppendNS(&path, (uint32_t)(token - fileName + 1), fileName); + CreateDirectoryA(path.chars, NULL); fileName = token + 1; } }