diff options
| author | Gabriel Schneider <[email protected]> | 2026-02-06 14:51:17 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-02-06 14:51:17 -0300 |
| commit | 632a8daeb6377bdfde47cf83dcffd116d88e999a (patch) | |
| tree | 566f0da3f5495c95611bf18bdccee695e602e082 /src/gloves.zig | |
| parent | 19101e2358f00cc8c4bebb320181e05f96080564 (diff) | |
| download | codenomicon-632a8daeb6377bdfde47cf83dcffd116d88e999a.tar.gz codenomicon-632a8daeb6377bdfde47cf83dcffd116d88e999a.zip | |
updated to zig 0.16.0 and fixed memory leaks
Diffstat (limited to 'src/gloves.zig')
| -rw-r--r-- | src/gloves.zig | 93 |
1 files changed, 50 insertions, 43 deletions
diff --git a/src/gloves.zig b/src/gloves.zig index b99df55..0ef2481 100644 --- a/src/gloves.zig +++ b/src/gloves.zig @@ -13,55 +13,62 @@ const alloc = gpa.allocator(); const ArrayList = std.ArrayList; pub fn main() !void { - var child = std.process.Child.init(&.{"./study-samples/split"}, alloc); - child.stdin_behavior = .Pipe; - child.stdout_behavior = .Pipe; - child.stderr_behavior = .Pipe; + // // var child = std.process.Child.init(&.{ "cat", "-" }, alloc); + // var child = std.process.Child.init(&.{"./study-samples/split"}, alloc); + // child.stdin_behavior = .Pipe; + // child.stdout_behavior = .Pipe; + // child.stderr_behavior = .Pipe; - var stdin_buf: [0x100]u8 = undefined; - var stdin = std.fs.File.stdin().readerStreaming(&stdin_buf); + // var stdin_buf: [0x100]u8 = undefined; + // var stdin = std.fs.File.stdin().readerStreaming(&stdin_buf); - var stdout: ArrayList(u8) = .empty; - defer stdout.deinit(alloc); - var stderr: ArrayList(u8) = .empty; - defer stderr.deinit(alloc); + // var stdout: ArrayList(u8) = .empty; + // defer stdout.deinit(alloc); + // var stderr: ArrayList(u8) = .empty; + // defer stderr.deinit(alloc); - try child.spawn(); + // try child.spawn(); + // errdefer { + // _ = child.kill() catch {}; + // } - var child_writer_buf: [0x100]u8 = undefined; - var child_stdin_writer = child.stdin.?.writer(&child_writer_buf); + // var child_writer_buf: [0x100]u8 = undefined; + // var child_stdin_writer = child.stdin.?.writer(&child_writer_buf); - while (true) { - if (stdin.interface.streamDelimiter(&child_stdin_writer.interface, '\n')) |_| {} else |_| { - break; - } - // if (n == 0) break; - _ = try child_stdin_writer.interface.writeByte('\n'); - if (child_stdin_writer.interface.flush()) |_| {} else |_| { - break; - } - try child.collectOutput(alloc, &stdout, &stderr, 0x1000); - std.debug.print("{s}\n {s}\n", .{ stdout.items, stderr.items }); - } + // while (true) { + // if (stdin.interface.streamDelimiter(&child_stdin_writer.interface, '\n')) |_| {} else |e| { + // switch (e) { + // error.EndOfStream => { + // std.debug.print("end of stream\n", .{}); + // break; + // }, + // else => {}, + // } + // break; + // } + // _ = try child_stdin_writer.interface.writeByte('\n'); + // if (child_stdin_writer.interface.flush()) |_| {} else |_| { + // break; + // } + // } - errdefer { - _ = child.kill() catch {}; - } + // child.collectOutput(alloc, &stdout, &stderr, 0x1000) catch {}; + // std.debug.print("{s}\n {s}\n", .{ stdout.items, stderr.items }); - const term = try child.wait(); - switch (term) { - .Signal => |s| { - inline for (@typeInfo(std.os.linux.SIG).@"struct".decls) |f| { - const field = @field(std.os.linux.SIG, f.name); - const t = @TypeOf(field); - if (t == comptime_int) { - if (field == s) - std.debug.print("Returned with Signal: {s} ({d})\n", .{ f.name, s }); - } - } - }, - else => std.debug.print("{any}\n", .{ .term = term }), - } + // const term = try child.wait(); + // switch (term) { + // .Signal => |s| { + // inline for (@typeInfo(std.os.linux.SIG).@"struct".decls) |f| { + // const field = @field(std.os.linux.SIG, f.name); + // const t = @TypeOf(field); + // if (t == comptime_int) { + // if (field == s) + // std.debug.print("Returned with Signal: {s} ({d})\n", .{ f.name, s }); + // } + // } + // }, + // else => std.debug.print("{any}\n", .{ .term = term }), + // } - // std.debug.print("*** If you this message alone... Something probably went wrong\nIs this leaking? {any}\n", .{gpa.detectLeaks()}); + // // std.debug.print("*** If you this message alone... Something probably went wrong\nIs this leaking? {any}\n", .{gpa.detectLeaks()}); } |
