summaryrefslogtreecommitdiff
path: root/src/cli/util.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 11:08:49 -0300
committerGabriel Schneider <[email protected]>2026-11-10 11:08:49 -0300
commit0b29354e1ddf6cf75ac4c426a00dd3435ace5069 (patch)
tree918e6f6810a9b8b5a8ed17e698085e92018333b9 /src/cli/util.zig
downloadcomputeranim-0b29354e1ddf6cf75ac4c426a00dd3435ace5069.tar.gz
computeranim-0b29354e1ddf6cf75ac4c426a00dd3435ace5069.zip
ztrace: the event, the ring, the recording, a ptrace loop
One 64-byte Event for every backend; a shared-memory ring from target to tracer with stop/resume; a Recorder that folds events into xitdb moments (registers, memory in 64-byte chunks with known-byte masks, strings) and a Trace that reads any moment back; a minimal ptrace Process; ztrace record, run and dump. Per-area build files so the areas grow apart.
Diffstat (limited to 'src/cli/util.zig')
-rw-r--r--src/cli/util.zig27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/cli/util.zig b/src/cli/util.zig
new file mode 100644
index 0000000..abdedd1
--- /dev/null
+++ b/src/cli/util.zig
@@ -0,0 +1,27 @@
+//! What every command needs.
+const std = @import("std");
+
+pub fn fail(comptime fmt: []const u8, args: anytype) noreturn {
+ std.debug.print(fmt, args);
+ std.process.exit(2);
+}
+
+/// `name` as a path: itself with a slash in it, else the first match in PATH.
+pub fn resolve(init: std.process.Init, name: [:0]const u8) ![*:0]const u8 {
+ if (std.mem.indexOfScalar(u8, name, '/') != null) return name.ptr;
+ const arena = init.arena.allocator();
+ var dirs = std.mem.tokenizeScalar(u8, init.environ_map.get("PATH") orelse "/usr/bin:/bin", ':');
+ while (dirs.next()) |dir| {
+ const candidate = try std.fs.path.joinZ(arena, &.{ dir, name });
+ std.Io.Dir.cwd().access(init.io, candidate, .{ .execute = true }) catch continue;
+ return candidate.ptr;
+ }
+ fail("{s}: not found in PATH\n", .{name});
+}
+
+/// The arguments after a command's own, as the target's argv.
+pub fn targetArgv(arena: std.mem.Allocator, args: []const [:0]const u8) ![:null]?[*:0]const u8 {
+ const argv = try arena.allocSentinel(?[*:0]const u8, args.len, null);
+ for (argv, args) |*dst, s| dst.* = s.ptr;
+ return argv;
+}