Skip to content

Commit

Permalink
Merge pull request #868 from der-teufel-programming/win-noxdg
Browse files Browse the repository at this point in the history
os/xdg: Add `LOCALAPPDATA` as a fallback for `XDG_CONFIG_HOME` on Windows
  • Loading branch information
mitchellh authored Nov 13, 2023
2 parents f3c4c87 + 0822e99 commit a8e82b1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/os/xdg.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ pub const Options = struct {
pub fn config(alloc: Allocator, opts: Options) ![]u8 {
// First check the env var. On Windows we have to allocate so this tracks
// both whether we have the env var and whether we own it.
// on Windows we treat `LOCALAPPDATA` as a fallback for `XDG_CONFIG_HOME`
const env_, const owned = switch (builtin.os.tag) {
else => .{ std.os.getenv("XDG_CONFIG_HOME"), false },
.windows => windows: {
if (std.process.getEnvVarOwned(alloc, "XDG_CONFIG_HOME")) |env| {
break :windows .{ env, true };
} else |err| switch (err) {
error.EnvironmentVariableNotFound => break :windows .{ null, false },
error.EnvironmentVariableNotFound => {
if (std.process.getEnvVarOwned(alloc, "LOCALAPPDATA")) |env| {
break :windows .{ env, true };
} else |err2| switch (err2) {
error.EnvironmentVariableNotFound => break :windows .{ null, false },
else => return err,
}
},
else => return err,
}
},
Expand Down

0 comments on commit a8e82b1

Please sign in to comment.