zig icon indicating copy to clipboard operation
zig copied to clipboard

Plan9: lots of fixes

Open g-w1 opened this issue 1 year ago • 0 comments

This enables this:

cpu% cat test.zig
const std = @import("std");
const p9 = std.os.plan9;
pub fn main() void {
    var buf: [50]u8 = undefined;
    const res = std.fmt.bufPrint(&buf, "argc: {d}, argv[0]: {s} argv[1]: {s} \n", .{ std.os.argv.len, std.os.argv[0], std.os.argv[1] }) catch blk: {
        print("we had an error bufprinting\n");
        break :blk "there was an error\n";
    };
    print(res);
    p9.exit(1);
}

pub fn print(str: []const u8) void {
    _ = p9.pwrite(1, str.ptr, str.len, 0);
}
cpu% ./test 'a short arg'
argc: 2, argv[0]: ./test argv[1]: a short arg 
cpu% ./test 'a really long arg that is quite long and will be too long for the buffer'
we had an error bufprinting
there was an error
cpu% ./test this should change argc
argc: 5, argv[0]: ./test argv[1]: this 
cpu% 

g-w1 avatar Jun 10 '23 23:06 g-w1