Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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 standard library. Private Function

findFromRoot

Private Function
std.zig.WindowsSdk.Installation.findFromRoot
fn findFromRoot(
        gpa: Allocator,
        io: Io,
        roots_key: Registry.Key,
        roots_subkey: []const u16,
        prefix: []const u8,
    ) error

Params

File

zig/WindowsSdk.zig:487
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
    fn findFromRoot(
        gpa: Allocator,
        io: Io,
        roots_key: Registry.Key,
        roots_subkey: []const u16,
        prefix: []const u8,
    ) error{ OutOfMemory, InstallationNotFound, PathTooLong, VersionTooLong }!Installation {
        const path = path: {
            const path_w_maybe_with_trailing_slash = roots_key.getString(gpa, .{ .name = roots_subkey }, .wtf16) catch |err| switch (err) {
                error.NotAString,
                error.ValueNameNotFound,
                error.StringNotFound,
                => return error.InstallationNotFound,

                error.OutOfMemory => |e| return e,
            };
            defer gpa.free(path_w_maybe_with_trailing_slash);

            if (!std.fs.path.isAbsoluteWindowsWtf16(path_w_maybe_with_trailing_slash)) {
                return error.InstallationNotFound;
            }

            const path_w = std.mem.trimEnd(u16, path_w_maybe_with_trailing_slash, L("\\/"));
            break :path try std.unicode.wtf16LeToWtf8Alloc(gpa, path_w);
        };
        errdefer gpa.free(path);

        const version = version: {
            var buf: [Dir.max_path_bytes]u8 = undefined;
            const sdk_lib_dir_path = std.mem.print(buf[0..], "{s}\\Lib\\", .{path}) catch |err| switch (err) {
                error.NoSpaceLeft => return error.PathTooLong,
            };
            if (!Dir.path.isAbsolute(sdk_lib_dir_path)) return error.InstallationNotFound;

            // enumerate files in sdk path looking for latest version
            var sdk_lib_dir = Dir.openDirAbsolute(io, sdk_lib_dir_path, .{
                .iterate = true,
            }) catch |err| switch (err) {
                error.NameTooLong => return error.PathTooLong,
                else => return error.InstallationNotFound,
            };
            defer sdk_lib_dir.close(io);

            var iterator = sdk_lib_dir.iterate();
            const versions = try iterateAndFilterByVersion(&iterator, gpa, io, prefix);
            if (versions.len == 0) return error.InstallationNotFound;
            defer {
                for (versions[1..]) |version| gpa.free(version);
                gpa.free(versions);
            }
            break :version versions[0];
        };
        errdefer gpa.free(version);

        return .{ .path = path, .version = version };
    }