~gpanders/wk

cdfd9318a66ce702d6514530f78b271e8018fb44 — Greg Anders 8 months ago 157b4a1
Use argsAlloc from standard library over custom func
1 files changed, 2 insertions(+), 15 deletions(-)

M src/main.zig
M src/main.zig => src/main.zig +2 -15
@@ 19,27 19,14 @@ fn zettelDir(allocator: *std.mem.Allocator) ![]const u8 {
    return try std.fs.path.resolve(allocator, &[_][]const u8{path});
}

fn parseArgs(allocator: *std.mem.Allocator) ![][]const u8 {
    var arglist = std.ArrayList([]const u8).init(allocator);
    defer arglist.deinit();

    var args = std.process.args();
    while (args.next(allocator)) |item_or_error| {
        const item = try item_or_error;
        try arglist.append(item);
    }

    return arglist.toOwnedSlice();
}

pub fn main() anyerror!void {
    var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
    defer arena.deinit();

    var allocator = &arena.allocator;

    const arglist = try parseArgs(allocator);
    defer allocator.free(arglist);
    const arglist = try std.process.argsAlloc(allocator);
    defer std.process.argsFree(allocator, arglist);

    const exe = arglist[0];
    if (arglist.len == 1) {