std.path
std.path: file paths as byte strings (`[]u8`).
Everything is lexical: nothing looks at the file system, so symbolic links are not followed. The separator is `/` only. The functions that pick a part of a path (`dirname`, `basename`, `extension`) return a slice of their input; the ones that build a new path take an `Allocator`.
join
pub fn join(alloc: Allocator, a: []u8, b: []u8) AllocError![]mut u8
`a` and `b` with exactly one `/` between them: the slashes at the end of `a` and at the start of `b` are replaced by it. Nothing else changes (`..` and `.` stay); if one part is empty the result is a copy of the other. The result is new memory from `alloc` (free it with `alloc.free`).
dirname
pub fn dirname(p: []u8) []u8
The directory part of `p`: everything before the last name, without the slashes that end it. `dirname("a/b/c")` is "a/b", `dirname("/a")` is "/". Slashes at the end of `p` are ignored. A path with no directory part gives "." (a constant, not a slice of `p`).
basename
pub fn basename(p: []u8) []u8
The last name of `p`, without slashes: `basename("a/b/")` is "b". It is empty for "" and for a path of slashes only.
extension
pub fn extension(p: []u8) []u8
The extension of the last name of `p`, with its dot: `extension("a/b.tar.gz")` is ".gz". It is empty when the name has no dot, when its only dot is the first character (".bashrc"), and for the names "." and "..".
normalize
pub fn normalize(alloc: Allocator, p: []u8) AllocError![]mut u8
`p` cleaned without looking at the file system: `.` names and empty names (from `//`) are dropped, `name/..` pairs are dropped, and a trailing `/` is dropped except for the root "/". A `..` that would go above the root of an absolute path is dropped ("/.." is "/"); a `..` that leads a relative path stays ("../a" is "../a"). A path with nothing left is ".". The result is new memory from `alloc` (free it with `alloc.free`).
isUnder
pub fn isUnder(alloc: Allocator, root: []u8, p: []u8) AllocError!bool
Is `p` the same path as `root`, or inside it? Both are normalized first, so "/srv/www/../a" is inside "/srv" and "/srv/../etc" is not. Whole names are compared ("/srv2" is not inside "/srv"). The check is lexical: "." as the root holds every relative path that does not start with `..`, and an absolute path is never inside a relative root or the other way round. Allocates the two normalized paths from `alloc` and frees them.