diff options
Diffstat (limited to 'src/dump.zig')
| -rw-r--r-- | src/dump.zig | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/dump.zig b/src/dump.zig index 7101b708..88a95994 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -53,20 +53,27 @@ pub fn outPath(buf: *[1024:0]u8, dir_setting: []const u8) ?[:0]const u8 { ds.getSecondsIntoMinute(), }, 0) catch null; } +/// The host's environment; a freestanding core (web, the board) has none +/// and no libc to ask, so only a DumpDir with no `~/` names a directory there. +fn hostEnv(name: [*:0]const u8) ?[*:0]u8 { + if (builtin.os.tag == .freestanding) return null; + return std.c.getenv(name); +} + /// Where dumps go and relative Restore names are looked up: the `DumpDir` /// setting when set (a leading `~/` is the home directory), else the default. pub fn directory(buf: []u8, dir_setting: []const u8) ?[]const u8 { if (dir_setting.len == 0) return defaultDirectory(buf); - if (std.mem.startsWith(u8, dir_setting, "~/")) if (std.c.getenv("HOME")) |h| + if (std.mem.startsWith(u8, dir_setting, "~/")) if (hostEnv("HOME")) |h| return std.fmt.bufPrint(buf, "{s}/{s}", .{ std.mem.span(h), dir_setting[2..] }) catch null; return std.fmt.bufPrint(buf, "{s}", .{dir_setting}) catch null; } /// The standard dump directory, without creating it or generating a filename. pub fn defaultDirectory(buf: []u8) ?[]const u8 { - if (std.c.getenv("XDG_DATA_HOME")) |x| + if (hostEnv("XDG_DATA_HOME")) |x| return std.fmt.bufPrint(buf, "{s}/pardes", .{std.mem.span(x)}) catch null; - if (std.c.getenv("HOME")) |h| + if (hostEnv("HOME")) |h| return std.fmt.bufPrint(buf, "{s}/.local/share/pardes", .{std.mem.span(h)}) catch null; return null; } |
