fn rootDir(path: []const u8, kind: FileKind) []const u8 path: []const u8kind: FileKind72
73
74
75
76
77
78
79
80
81
82
83
84
85 fn rootDir(path: []const u8, kind: FileKind) []const u8 {
const start_index: usize = if (path[0] == '/') 1 else 0;
const end_index: usize = if (path[path.len - 1] == '/') path.len - 1 else path.len;
const buf = path[start_index..end_index];
if (std.mem.findScalarPos(u8, buf, 0, '/')) |idx| {
return buf[0..idx];
}
return switch (kind) {
.file => "",
.sym_link => "",
.directory => buf,
};
}
Returns root dir of the path, assumes non empty path.