blob: ed9e628d20d9aad60f5aa4848514ab049e15a272 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
const std = @import("std");
const Allocator = std.mem.Allocator;
pub fn resolvePath(allocator: Allocator, name: []const u8) ![]u8 {
return std.fs.cwd().realpathAlloc(allocator, name) catch |err| switch (err) {
error.FileNotFound => if (name.len == 0) {
return error.FileNotFound;
} else if (name[0] == std.fs.path.sep) {
// Already is an absolute path
return allocator.dupe(u8, name);
} else {
// TODO: if (name[0] == '~')
const cwd = try std.process.getCwdAlloc(allocator);
defer allocator.free(cwd);
return std.fmt.allocPrint(allocator, "{s}{s}{s}", .{cwd, std.fs.path.sep_str, name});
},
else => return err,
};
}
|