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.

validateSearchPath

Very crude attempt at validating a path. This is imperfect and AFAIK it is effectively impossible to implement perfect path validation, since it ultimately depends on the underlying filesystem. Note that this function won't be necessary if/when https://github.com/ziglang/zig/issues/15607 is accepted/implemented.

compile.validateSearchPath
fn validateSearchPath(path: []const u8) error

File

lib/compiler/resinator/compile.zig:2912

Code

fn validateSearchPath(path: []const u8) error{BadPathName}!void {
    switch (builtin.os.tag) {
        .windows => {
            // This will return error.BadPathName on non-Win32 namespaced paths
            // (e.g. the NT \??\ prefix, the device \\.\ prefix, etc).
            // Those path types are something of an unavoidable way to
            // still hit unreachable during the openDir call.
            var component_iterator = std.fs.path.componentIterator(path);
            while (component_iterator.next()) |component| {
                // https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
                if (std.mem.indexOfAny(u8, component.name, "\x00<>:\"|?*") != null) return error.BadPathName;
            }
        },
        else => {
            if (std.mem.indexOfScalar(u8, path, 0) != null) return error.BadPathName;
        },
    }
}