feature(IO): support searching user's config file from configDirs

This commit is contained in:
apocelipes
2023-12-20 16:41:24 +09:00
committed by Carter Li
parent a4f5a9af03
commit b9368ac20d
+16
View File
@@ -1,6 +1,7 @@
#pragma once
#include "util/FFstrbuf.h"
#include "util/FFlist.h"
#ifdef _WIN32
#include <fileapi.h>
@@ -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;
}