Integrate with herdr cli.

This commit is contained in:
Greyson Parrelli committed 2026-11-02 10:47:08 -05:00
1 parent baa2907391
commit b5af181a4d
11 files changed
+1641 -93

No files matched your search

+8 -2
View File
@@ -241,7 +241,7 @@ fn buildEnv(
/// Whether an inherited `NAME=value` entry names a variable the caller is
/// about to define.
fn shadowedBy(entry: []const u8, extra: []const []const u8) bool {
pub fn shadowedBy(entry: []const u8, extra: []const []const u8) bool {
const eq = std.mem.indexOfScalar(u8, entry, '=') orelse return false;
for (extra) |candidate| {
const candidate_eq = std.mem.indexOfScalar(u8, candidate, '=') orelse continue;
@@ -263,8 +263,14 @@ fn freeEnv(alloc: std.mem.Allocator, envp: [:null]?[*:0]const u8) void {
/// are rather than where you began. Read straight out of procfs: there is no
/// portable API for it, and this app is Linux-only regardless.
pub fn cwd(self: Pty, buf: []u8) ?[]const u8 {
return cwdOf(self.pid, buf);
}
/// `cwd` for any process, not only one this module started — a herdr-core
/// terminal's program, which runs on this machine but is nobody's child here.
pub fn cwdOf(pid: pid_t, buf: []u8) ?[]const u8 {
var link_buf: [64]u8 = undefined;
const link = std.mem.printSentinel(&link_buf, "/proc/{d}/cwd", .{self.pid}, 0) catch return null;
const link = std.mem.printSentinel(&link_buf, "/proc/{d}/cwd", .{pid}, 0) catch return null;
const n = c.readlink(link.ptr, buf.ptr, buf.len);
if (n <= 0) return null;