aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug/Dwarf.zig
diff options
context:
space:
mode:
authorIan Johnson <ian@ianjohnson.dev>2024-08-19 23:11:32 -0400
committerAndrew Kelley <andrew@ziglang.org>2024-08-19 23:30:14 -0700
commit0a70455095a19a4c18497e6786ca6139c1cc2892 (patch)
treee3b5ca0499e459ac413a2e4152dcae5ad6a9b833 /lib/std/debug/Dwarf.zig
parentdffc8c44f9a01aa05ea364ffdc71509d15bc2601 (diff)
downloadzig-0a70455095a19a4c18497e6786ca6139c1cc2892.tar.gz
zig-0a70455095a19a4c18497e6786ca6139c1cc2892.zip
Fix handling of empty XDG environment variables
Closes #21132 According to the XDG Base Directory specification (https://specifications.freedesktop.org/basedir-spec/latest/#variables), empty values for these environment variables should be treated the same as if they are unset. Specifically, for the instances changed in this commit, > $XDG_DATA_HOME defines the base directory relative to which > user-specific data files should be stored. If $XDG_DATA_HOME is either > not set **or empty**, a default equal to $HOME/.local/share should be > used. and > $XDG_CACHE_HOME defines the base directory relative to which > user-specific non-essential data files should be stored. If > $XDG_CACHE_HOME is either not set **or empty**, a default equal to > $HOME/.cache should be used. (emphasis mine) In addition to the case mentioned in the linked issue, all other uses of XDG environment variables were corrected.
Diffstat (limited to 'lib/std/debug/Dwarf.zig')
-rw-r--r--lib/std/debug/Dwarf.zig8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/std/debug/Dwarf.zig b/lib/std/debug/Dwarf.zig
index fb72316675..7cce30df38 100644
--- a/lib/std/debug/Dwarf.zig
+++ b/lib/std/debug/Dwarf.zig
@@ -2275,9 +2275,11 @@ pub const ElfModule = struct {
break :dir std.fs.openDirAbsolute(path, .{}) catch break :blk;
}
if (std.posix.getenv("XDG_CACHE_HOME")) |cache_path| {
- const path = std.fs.path.join(gpa, &[_][]const u8{ cache_path, "debuginfod_client" }) catch break :blk;
- defer gpa.free(path);
- break :dir std.fs.openDirAbsolute(path, .{}) catch break :blk;
+ if (cache_path.len > 0) {
+ const path = std.fs.path.join(gpa, &[_][]const u8{ cache_path, "debuginfod_client" }) catch break :blk;
+ defer gpa.free(path);
+ break :dir std.fs.openDirAbsolute(path, .{}) catch break :blk;
+ }
}
if (std.posix.getenv("HOME")) |home_path| {
const path = std.fs.path.join(gpa, &[_][]const u8{ home_path, ".cache", "debuginfod_client" }) catch break :blk;