std/fs: Support XDG_DATA_HOME

This is generally used for user-specific data on linux, with the
default being ~/.local/share
This commit is contained in:
fifty-six 2022-01-19 16:09:48 -05:00 committed by Veikka Tuominen
parent 1f10cf4edf
commit da8d4d9225

View File

@ -45,6 +45,10 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi
return fs.path.join(allocator, &[_][]const u8{ home_dir, "Library", "Application Support", appname });
},
.linux, .freebsd, .netbsd, .dragonfly, .openbsd, .solaris => {
if (os.getenv("XDG_DATA_HOME")) |xdg| {
return fs.path.join(allocator, &[_][]const u8{ xdg, appname });
}
const home_dir = os.getenv("HOME") orelse {
// TODO look in /etc/passwd
return error.AppDataDirUnavailable;