From b9368ac20d95a489ae58ff468c131045606d6e07 Mon Sep 17 00:00:00 2001 From: apocelipes Date: Wed, 20 Dec 2023 16:41:24 +0900 Subject: [PATCH] feature(IO): support searching user's config file from configDirs --- src/common/io/io.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/common/io/io.h b/src/common/io/io.h index 257e9ce83..ec3375bd0 100644 --- a/src/common/io/io.h +++ b/src/common/io/io.h @@ -1,6 +1,7 @@ #pragma once #include "util/FFstrbuf.h" +#include "util/FFlist.h" #ifdef _WIN32 #include @@ -185,3 +186,18 @@ static inline bool wrapClosedir(HANDLE* pdir) } #endif #define FF_AUTO_CLOSE_DIR __attribute__((__cleanup__(wrapClosedir))) + +static inline bool ffSearchUserConfigFile(const FFlist* configDirs, const char* fileSubpath, FFstrbuf* result) +{ + // configDirs is a list of FFstrbufs include the trailing slash + FF_LIST_FOR_EACH(FFstrbuf, dir, *configDirs) + { + ffStrbufClear(result); + ffStrbufAppend(result, dir); + ffStrbufAppendS(result, fileSubpath); + if (ffPathExists(result->chars, FF_PATHTYPE_FILE)) + return true; + } + + return false; +}