#How to get the basename of the working directory?
1 messages · Page 1 of 1 (latest)
This works for me, although it feels a bit hacky.
zigconst std = @import("std");
const fs = std.fs;
const debug = std.debug;
pub fn main() !void {
var buf: [1024]u8 = undefined;
const path = try fs.cwd().realpath(".", &buf);
debug.print("{s}\n", .{path});
}
no, realpath is not what i wait. it resolves symlinks and stuff.
Maybe you can copy how getcwd() in libc is implemented`
Actually I just checked and there is std.os.getcwd(). It returns the absolute path, but you can use std.fs.path.basename() to get the basename. Not sure if it resolves symlinks; At least on linux it's a single syscall and the man page for the POSIX function gives no clue.
yea seems good. questionable API design tho 😛
All of POSIX is questionable 🙂