stage1: add linux XDG Base Directory support
- define zig global cache based on XDG spec:
if env XDG_CACHE_HOME {
"$XDG_CACHE_HOME/zig"
} else {
"$HOME/.cache/zig"
}
- old definition "$HOME/.local/share/zig" is retired
- closes #3573
This commit is contained in:
committed by
Andrew Kelley
parent
2e0dd5733f
commit
10046f9a52
39
src/os.cpp
39
src/os.cpp
@@ -1748,7 +1748,7 @@ static void utf16le_ptr_to_utf8(Buf *out, WCHAR *utf16le) {
|
||||
#endif
|
||||
|
||||
// Ported from std.os.getAppDataDir
|
||||
Error os_get_app_data_dir(Buf *out_path, const char *appname) {
|
||||
Error os_get_cache_dir(Buf *out_path, const char *appname) {
|
||||
#if defined(ZIG_OS_WINDOWS)
|
||||
WCHAR *dir_path_ptr;
|
||||
switch (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, nullptr, &dir_path_ptr)) {
|
||||
@@ -1774,24 +1774,35 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) {
|
||||
buf_appendf(out_path, "%s/Library/Application Support/%s", home_dir, appname);
|
||||
return ErrorNone;
|
||||
#elif defined(ZIG_OS_POSIX)
|
||||
const char *home_dir = getenv("HOME");
|
||||
if (home_dir == nullptr) {
|
||||
// TODO use /etc/passwd
|
||||
return ErrorFileNotFound;
|
||||
const char *cache_dir = getenv("XDG_CACHE_HOME");
|
||||
if (cache_dir == nullptr) {
|
||||
cache_dir = getenv("HOME");
|
||||
if (cache_dir == nullptr) {
|
||||
// TODO use /etc/passwd
|
||||
return ErrorFileNotFound;
|
||||
}
|
||||
if (cache_dir[0] == 0) {
|
||||
return ErrorFileNotFound;
|
||||
}
|
||||
buf_init_from_str(out_path, cache_dir);
|
||||
if (buf_ptr(out_path)[buf_len(out_path) - 1] != '/') {
|
||||
buf_append_char(out_path, '/');
|
||||
}
|
||||
buf_appendf(out_path, ".cache/%s", appname);
|
||||
} else {
|
||||
if (cache_dir[0] == 0) {
|
||||
return ErrorFileNotFound;
|
||||
}
|
||||
buf_init_from_str(out_path, cache_dir);
|
||||
if (buf_ptr(out_path)[buf_len(out_path) - 1] != '/') {
|
||||
buf_append_char(out_path, '/');
|
||||
}
|
||||
buf_appendf(out_path, "%s", appname);
|
||||
}
|
||||
if (home_dir[0] == 0) {
|
||||
return ErrorFileNotFound;
|
||||
}
|
||||
buf_init_from_str(out_path, home_dir);
|
||||
if (buf_ptr(out_path)[buf_len(out_path) - 1] != '/') {
|
||||
buf_append_char(out_path, '/');
|
||||
}
|
||||
buf_appendf(out_path, ".local/share/%s", appname);
|
||||
return ErrorNone;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY)
|
||||
static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) {
|
||||
ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data);
|
||||
|
||||
Reference in New Issue
Block a user