| ... | ... | @@ -35,15 +35,21 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD |
| 35 | 35 | else => return error.AppDataDirUnavailable, |
| 36 | 36 | } |
| 37 | 37 | }, |
| 38 | | // TODO for macos it should be "~/Library/Application Support/<APPNAME>" |
| 39 | | else => { |
| 40 | | const home_dir = os.getEnvVarOwned(allocator, "HOME") catch |err| switch (err) { |
| 41 | | error.OutOfMemory => return error.OutOfMemory, |
| 42 | | error.EnvironmentVariableNotFound => return error.AppDataDirUnavailable, // TODO look in /etc/passwd |
| 38 | builtin.Os.macosx => { |
| 39 | const home_dir = os.getEnvPosix("HOME") orelse { |
| 40 | // TODO look in /etc/passwd |
| 41 | return error.AppDataDirUnavailable; |
| 42 | }; |
| 43 | return os.path.join(allocator, home_dir, "Library", "Application Support", appname); |
| 44 | }, |
| 45 | builtin.Os.linux => { |
| 46 | const home_dir = os.getEnvPosix("HOME") orelse { |
| 47 | // TODO look in /etc/passwd |
| 48 | return error.AppDataDirUnavailable; |
| 43 | 49 | }; |
| 44 | | defer allocator.free(home_dir); |
| 45 | 50 | return os.path.join(allocator, home_dir, ".local", "share", appname); |
| 46 | 51 | }, |
| 52 | else => @compileError("Unsupported OS"), |
| 47 | 53 | } |
| 48 | 54 | } |
| 49 | 55 | |
| ... | ... | @@ -53,8 +59,11 @@ fn utf16lePtrSlice(ptr: [*]const u16) []const u16 { |
| 53 | 59 | return ptr[0..index]; |
| 54 | 60 | } |
| 55 | 61 | |
| 56 | | test "getAppDataDir" { |
| 57 | | const result = try getAppDataDir(std.debug.global_allocator, "zig"); |
| 58 | | std.debug.warn("{}...", result); |
| 62 | test "std.os.getAppDataDir" { |
| 63 | var buf: [512]u8 = undefined; |
| 64 | const allocator = &std.heap.FixedBufferAllocator.init(buf[0..]).allocator; |
| 65 | |
| 66 | // We can't actually validate the result |
| 67 | _ = getAppDataDir(allocator, "zig") catch return; |
| 59 | 68 | } |
| 60 | 69 | |