Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

checkCandidate

FindProgram.checkCandidate
fn checkCandidate(
    maker: *Maker,
    step: *Step,
    found_path: Configuration.GeneratedFileIndex,
    err_msg: *std.ArrayList(u8),
    full_path: []const u8,
) !bool

File

lib/compiler/Maker/Step/FindProgram.zig:68

Code

fn checkCandidate(
    maker: *Maker,
    step: *Step,
    found_path: Configuration.GeneratedFileIndex,
    err_msg: *std.ArrayList(u8),
    full_path: []const u8,
) !bool {
    const graph = maker.graph;
    const arena = graph.arena; // TODO don't leak into process arena
    const io = graph.io;

    if (Io.Dir.cwd().access(io, full_path, .{ .execute = true })) |_| {
        maker.generatedPath(found_path).* = .initCwd(full_path);
        return true;
    } else |err| switch (err) {
        error.Canceled => |e| return e,
        error.FileNotFound, error.AccessDenied, error.PermissionDenied => |e| {
            try err_msg.print(arena, "{t} {s}\n", .{ e, full_path });
        },
        else => |e| return step.fail(maker, "failed accessing {s}: {t}", .{ full_path, e }),
    }

    if (builtin.os.tag == .windows) {
        if (graph.environ_map.get("PATHEXT")) |PATHEXT| {
            var it = std.mem.tokenizeScalar(u8, PATHEXT, Io.Dir.path.delimiter);
            while (it.next()) |ext| {
                if (!supportedWindowsProgramExtension(ext)) continue;

                const extended_path = try std.mem.concat(arena, u8, &.{ full_path, ext });

                if (Io.Dir.cwd().access(io, extended_path, .{ .execute = true })) |_| {
                    maker.generatedPath(found_path).* = .initCwd(extended_path);
                    return true;
                } else |err| switch (err) {
                    error.Canceled => |e| return e,
                    error.FileNotFound, error.AccessDenied, error.PermissionDenied => |e| {
                        try err_msg.print(arena, "{t} {s}\n", .{ e, extended_path });
                    },
                    else => |e| return step.fail(maker, "failed accessing {s}: {t}", .{ extended_path, e }),
                }
            }
        }
    }

    return false;
}