Skip to content

Commit bf2d961

Browse files
committed
Add support for APPDATA directory on Windows
Fixes #3
1 parent 0299c77 commit bf2d961

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/common/fs.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,15 @@ static fs_path_t fs_win32_posix_tmp_dir(void) {
561561

562562
static fs_path_t fs_win32_posix_config_dir(void) {
563563
#if defined(WIN32)
564+
const WCHAR* wc_appdata = _wgetenv(L"APPDATA");
565+
if (wc_appdata && wc_appdata[0]) {
566+
char utf8_appdata[FS_PATH_SIZE];
567+
if (0 != WideCharToMultiByte(CP_UTF8, 0, wc_appdata, -1, utf8_appdata,
568+
sizeof(utf8_appdata), NULL, NULL)) {
569+
return fs_path_printf("%s", utf8_appdata);
570+
}
571+
}
572+
// Fall back to the temp directory if %APPDATA% is unavailable.
564573
return fs_win32_posix_tmp_dir();
565574
#else
566575
const char *xdg_config_home = getenv("XDG_CONFIG_HOME");

0 commit comments

Comments
 (0)