authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-08 13:39:09-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:08-08:00
logf53248a40936ebc9aaf75ddbd16e67ebec05ab84
treeaf6a1a4fa4d3ff09dae241922a8f7c37cde43681
parent916998315967f73c91e682e9ea05dd3232818654

update all std.fs.cwd() to std.Io.Dir.cwd()


72 files changed, 398 insertions(+), 377 deletions(-)

lib/compiler/aro/aro/Compilation.zig+4-4
......@@ -2253,7 +2253,7 @@ test "addSourceFromBuffer" {
22532253 var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
22542254 defer arena.deinit();
22552255 var diagnostics: Diagnostics = .{ .output = .ignore };
2256 var comp = Compilation.init(std.testing.allocator, arena.allocator(), std.testing.io, &diagnostics, std.fs.cwd());
2256 var comp = Compilation.init(std.testing.allocator, arena.allocator(), std.testing.io, &diagnostics, Io.Dir.cwd());
22572257 defer comp.deinit();
22582258
22592259 const source = try comp.addSourceFromBuffer("path", str);
......@@ -2267,7 +2267,7 @@ test "addSourceFromBuffer" {
22672267 var arena: std.heap.ArenaAllocator = .init(allocator);
22682268 defer arena.deinit();
22692269 var diagnostics: Diagnostics = .{ .output = .ignore };
2270 var comp = Compilation.init(allocator, arena.allocator(), std.testing.io, &diagnostics, std.fs.cwd());
2270 var comp = Compilation.init(allocator, arena.allocator(), std.testing.io, &diagnostics, Io.Dir.cwd());
22712271 defer comp.deinit();
22722272
22732273 _ = try comp.addSourceFromBuffer("path", "spliced\\\nbuffer\n");
......@@ -2313,7 +2313,7 @@ test "addSourceFromBuffer - exhaustive check for carriage return elimination" {
23132313 var buf: [alphabet.len]u8 = @splat(alphabet[0]);
23142314
23152315 var diagnostics: Diagnostics = .{ .output = .ignore };
2316 var comp = Compilation.init(std.testing.allocator, arena.allocator(), std.testing.io, &diagnostics, std.fs.cwd());
2316 var comp = Compilation.init(std.testing.allocator, arena.allocator(), std.testing.io, &diagnostics, Io.Dir.cwd());
23172317 defer comp.deinit();
23182318
23192319 var source_count: u32 = 0;
......@@ -2341,7 +2341,7 @@ test "ignore BOM at beginning of file" {
23412341 const Test = struct {
23422342 fn run(arena: Allocator, buf: []const u8) !void {
23432343 var diagnostics: Diagnostics = .{ .output = .ignore };
2344 var comp = Compilation.init(std.testing.allocator, arena, std.testing.io, &diagnostics, std.fs.cwd());
2344 var comp = Compilation.init(std.testing.allocator, arena, std.testing.io, &diagnostics, Io.Dir.cwd());
23452345 defer comp.deinit();
23462346
23472347 const source = try comp.addSourceFromBuffer("file.c", buf);
lib/compiler/aro/aro/Driver.zig+5-5
......@@ -1327,7 +1327,7 @@ fn processSource(
13271327 const dep_file_name = try d.getDepFileName(source, writer_buf[0..std.fs.max_name_bytes]);
13281328
13291329 const file = if (dep_file_name) |path|
1330 d.comp.cwd.createFile(path, .{}) catch |er|
1330 d.comp.cwd.createFile(io, path, .{}) catch |er|
13311331 return d.fatal("unable to create dependency file '{s}': {s}", .{ path, errorDescription(er) })
13321332 else
13331333 Io.File.stdout();
......@@ -1352,7 +1352,7 @@ fn processSource(
13521352 }
13531353
13541354 const file = if (d.output_name) |some|
1355 d.comp.cwd.createFile(some, .{}) catch |er|
1355 d.comp.cwd.createFile(io, some, .{}) catch |er|
13561356 return d.fatal("unable to create output file '{s}': {s}", .{ some, errorDescription(er) })
13571357 else
13581358 Io.File.stdout();
......@@ -1405,7 +1405,7 @@ fn processSource(
14051405 defer assembly.deinit(gpa);
14061406
14071407 if (d.only_preprocess_and_compile) {
1408 const out_file = d.comp.cwd.createFile(out_file_name, .{}) catch |er|
1408 const out_file = d.comp.cwd.createFile(io, out_file_name, .{}) catch |er|
14091409 return d.fatal("unable to create output file '{s}': {s}", .{ out_file_name, errorDescription(er) });
14101410 defer out_file.close(io);
14111411
......@@ -1419,7 +1419,7 @@ fn processSource(
14191419 // then assemble to out_file_name
14201420 var assembly_name_buf: [std.fs.max_name_bytes]u8 = undefined;
14211421 const assembly_out_file_name = try d.getRandomFilename(&assembly_name_buf, ".s");
1422 const out_file = d.comp.cwd.createFile(assembly_out_file_name, .{}) catch |er|
1422 const out_file = d.comp.cwd.createFile(io, assembly_out_file_name, .{}) catch |er|
14231423 return d.fatal("unable to create output file '{s}': {s}", .{ assembly_out_file_name, errorDescription(er) });
14241424 defer out_file.close(io);
14251425 assembly.writeToFile(out_file) catch |er|
......@@ -1455,7 +1455,7 @@ fn processSource(
14551455 };
14561456 defer obj.deinit();
14571457
1458 const out_file = d.comp.cwd.createFile(out_file_name, .{}) catch |er|
1458 const out_file = d.comp.cwd.createFile(io, out_file_name, .{}) catch |er|
14591459 return d.fatal("unable to create output file '{s}': {s}", .{ out_file_name, errorDescription(er) });
14601460 defer out_file.close(io);
14611461
lib/compiler/aro/aro/Parser.zig+14-13
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const Io = std.Io;
23const mem = std.mem;
34const Allocator = mem.Allocator;
45const assert = std.debug.assert;
......@@ -211,7 +212,7 @@ fn checkIdentifierCodepointWarnings(p: *Parser, codepoint: u21, loc: Source.Loca
211212
212213 const prev_total = p.diagnostics.total;
213214 var sf = std.heap.stackFallback(1024, p.comp.gpa);
214 var allocating: std.Io.Writer.Allocating = .init(sf.get());
215 var allocating: Io.Writer.Allocating = .init(sf.get());
215216 defer allocating.deinit();
216217
217218 if (!char_info.isC99IdChar(codepoint)) {
......@@ -425,7 +426,7 @@ pub fn err(p: *Parser, tok_i: TokenIndex, diagnostic: Diagnostic, args: anytype)
425426 if (p.diagnostics.effectiveKind(diagnostic) == .off) return;
426427
427428 var sf = std.heap.stackFallback(1024, p.comp.gpa);
428 var allocating: std.Io.Writer.Allocating = .init(sf.get());
429 var allocating: Io.Writer.Allocating = .init(sf.get());
429430 defer allocating.deinit();
430431
431432 p.formatArgs(&allocating.writer, diagnostic.fmt, args) catch return error.OutOfMemory;
......@@ -447,7 +448,7 @@ pub fn err(p: *Parser, tok_i: TokenIndex, diagnostic: Diagnostic, args: anytype)
447448 }, p.pp.expansionSlice(tok_i), true);
448449}
449450
450fn formatArgs(p: *Parser, w: *std.Io.Writer, fmt: []const u8, args: anytype) !void {
451fn formatArgs(p: *Parser, w: *Io.Writer, fmt: []const u8, args: anytype) !void {
451452 var i: usize = 0;
452453 inline for (std.meta.fields(@TypeOf(args))) |arg_info| {
453454 const arg = @field(args, arg_info.name);
......@@ -476,13 +477,13 @@ fn formatArgs(p: *Parser, w: *std.Io.Writer, fmt: []const u8, args: anytype) !vo
476477 try w.writeAll(fmt[i..]);
477478}
478479
479fn formatTokenId(w: *std.Io.Writer, fmt: []const u8, tok_id: Tree.Token.Id) !usize {
480fn formatTokenId(w: *Io.Writer, fmt: []const u8, tok_id: Tree.Token.Id) !usize {
480481 const i = Diagnostics.templateIndex(w, fmt, "{tok_id}");
481482 try w.writeAll(tok_id.symbol());
482483 return i;
483484}
484485
485fn formatQualType(p: *Parser, w: *std.Io.Writer, fmt: []const u8, qt: QualType) !usize {
486fn formatQualType(p: *Parser, w: *Io.Writer, fmt: []const u8, qt: QualType) !usize {
486487 const i = Diagnostics.templateIndex(w, fmt, "{qt}");
487488 try w.writeByte('\'');
488489 try qt.print(p.comp, w);
......@@ -501,7 +502,7 @@ fn formatQualType(p: *Parser, w: *std.Io.Writer, fmt: []const u8, qt: QualType)
501502 return i;
502503}
503504
504fn formatResult(p: *Parser, w: *std.Io.Writer, fmt: []const u8, res: Result) !usize {
505fn formatResult(p: *Parser, w: *Io.Writer, fmt: []const u8, res: Result) !usize {
505506 const i = Diagnostics.templateIndex(w, fmt, "{value}");
506507 switch (res.val.opt_ref) {
507508 .none => try w.writeAll("(none)"),
......@@ -524,7 +525,7 @@ const Normalized = struct {
524525 return .{ .str = str };
525526 }
526527
527 pub fn format(ctx: Normalized, w: *std.Io.Writer, fmt: []const u8) !usize {
528 pub fn format(ctx: Normalized, w: *Io.Writer, fmt: []const u8) !usize {
528529 const i = Diagnostics.templateIndex(w, fmt, "{normalized}");
529530 var it: std.unicode.Utf8Iterator = .{
530531 .bytes = ctx.str,
......@@ -558,7 +559,7 @@ const Codepoint = struct {
558559 return .{ .codepoint = codepoint };
559560 }
560561
561 pub fn format(ctx: Codepoint, w: *std.Io.Writer, fmt: []const u8) !usize {
562 pub fn format(ctx: Codepoint, w: *Io.Writer, fmt: []const u8) !usize {
562563 const i = Diagnostics.templateIndex(w, fmt, "{codepoint}");
563564 try w.print("{X:0>4}", .{ctx.codepoint});
564565 return i;
......@@ -572,7 +573,7 @@ const Escaped = struct {
572573 return .{ .str = str };
573574 }
574575
575 pub fn format(ctx: Escaped, w: *std.Io.Writer, fmt: []const u8) !usize {
576 pub fn format(ctx: Escaped, w: *Io.Writer, fmt: []const u8) !usize {
576577 const i = Diagnostics.templateIndex(w, fmt, "{s}");
577578 try std.zig.stringEscape(ctx.str, w);
578579 return i;
......@@ -1453,7 +1454,7 @@ fn decl(p: *Parser) Error!bool {
14531454 return true;
14541455}
14551456
1456fn staticAssertMessage(p: *Parser, cond_node: Node.Index, maybe_message: ?Result, allocating: *std.Io.Writer.Allocating) !?[]const u8 {
1457fn staticAssertMessage(p: *Parser, cond_node: Node.Index, maybe_message: ?Result, allocating: *Io.Writer.Allocating) !?[]const u8 {
14571458 const w = &allocating.writer;
14581459
14591460 const cond = cond_node.get(&p.tree);
......@@ -1526,7 +1527,7 @@ fn staticAssert(p: *Parser) Error!bool {
15261527 } else {
15271528 if (!res.val.toBool(p.comp)) {
15281529 var sf = std.heap.stackFallback(1024, gpa);
1529 var allocating: std.Io.Writer.Allocating = .init(sf.get());
1530 var allocating: Io.Writer.Allocating = .init(sf.get());
15301531 defer allocating.deinit();
15311532
15321533 if (p.staticAssertMessage(res_node, str, &allocating) catch return error.OutOfMemory) |message| {
......@@ -9719,7 +9720,7 @@ fn primaryExpr(p: *Parser) Error!?Result {
97199720 qt = some.qt;
97209721 } else if (p.func.qt) |func_qt| {
97219722 var sf = std.heap.stackFallback(1024, gpa);
9722 var allocating: std.Io.Writer.Allocating = .init(sf.get());
9723 var allocating: Io.Writer.Allocating = .init(sf.get());
97239724 defer allocating.deinit();
97249725
97259726 func_qt.printNamed(p.tokSlice(p.func.name), p.comp, &allocating.writer) catch return error.OutOfMemory;
......@@ -10608,7 +10609,7 @@ test "Node locations" {
1060810609 const arena = arena_state.allocator();
1060910610
1061010611 var diagnostics: Diagnostics = .{ .output = .ignore };
10611 var comp = Compilation.init(std.testing.allocator, arena, std.testing.io, &diagnostics, std.fs.cwd());
10612 var comp = Compilation.init(std.testing.allocator, arena, std.testing.io, &diagnostics, Io.Dir.cwd());
1061210613 defer comp.deinit();
1061310614
1061410615 const file = try comp.addSourceFromBuffer("file.c",
lib/compiler/aro/aro/Preprocessor.zig+3-3
......@@ -3900,7 +3900,7 @@ test "Preserve pragma tokens sometimes" {
39003900 defer arena.deinit();
39013901
39023902 var diagnostics: Diagnostics = .{ .output = .ignore };
3903 var comp = Compilation.init(gpa, arena.allocator(), std.testing.io, &diagnostics, std.fs.cwd());
3903 var comp = Compilation.init(gpa, arena.allocator(), std.testing.io, &diagnostics, Io.Dir.cwd());
39043904 defer comp.deinit();
39053905
39063906 try comp.addDefaultPragmaHandlers();
......@@ -3967,7 +3967,7 @@ test "destringify" {
39673967 var arena: std.heap.ArenaAllocator = .init(gpa);
39683968 defer arena.deinit();
39693969 var diagnostics: Diagnostics = .{ .output = .ignore };
3970 var comp = Compilation.init(gpa, arena.allocator(), std.testing.io, &diagnostics, std.fs.cwd());
3970 var comp = Compilation.init(gpa, arena.allocator(), std.testing.io, &diagnostics, Io.Dir.cwd());
39713971 defer comp.deinit();
39723972 var pp = Preprocessor.init(&comp, .default);
39733973 defer pp.deinit();
......@@ -4030,7 +4030,7 @@ test "Include guards" {
40304030 const arena = arena_state.allocator();
40314031
40324032 var diagnostics: Diagnostics = .{ .output = .ignore };
4033 var comp = Compilation.init(gpa, arena, std.testing.io, &diagnostics, std.fs.cwd());
4033 var comp = Compilation.init(gpa, arena, std.testing.io, &diagnostics, Io.Dir.cwd());
40344034 defer comp.deinit();
40354035 var pp = Preprocessor.init(&comp, .default);
40364036 defer pp.deinit();
lib/compiler/aro/aro/Tokenizer.zig+3-2
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const Io = std.Io;
23const assert = std.debug.assert;
34
45const Compilation = @import("Compilation.zig");
......@@ -2326,7 +2327,7 @@ test "Tokenizer fuzz test" {
23262327 fn testOne(_: @This(), input_bytes: []const u8) anyerror!void {
23272328 var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
23282329 defer arena.deinit();
2329 var comp = Compilation.init(std.testing.allocator, arena.allocator(), std.testing.io, undefined, std.fs.cwd());
2330 var comp = Compilation.init(std.testing.allocator, arena.allocator(), std.testing.io, undefined, Io.Dir.cwd());
23302331 defer comp.deinit();
23312332
23322333 const source = try comp.addSourceFromBuffer("fuzz.c", input_bytes);
......@@ -2351,7 +2352,7 @@ test "Tokenizer fuzz test" {
23512352fn expectTokensExtra(contents: []const u8, expected_tokens: []const Token.Id, langopts: ?LangOpts) !void {
23522353 var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
23532354 defer arena.deinit();
2354 var comp = Compilation.init(std.testing.allocator, arena.allocator(), std.testing.io, undefined, std.fs.cwd());
2355 var comp = Compilation.init(std.testing.allocator, arena.allocator(), std.testing.io, undefined, Io.Dir.cwd());
23552356 defer comp.deinit();
23562357 if (langopts) |provided| {
23572358 comp.langopts = provided;
lib/compiler/aro/aro/Value.zig+6-5
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const Io = std.Io;
23const assert = std.debug.assert;
34const BigIntConst = std.math.big.int.Const;
45const BigIntMutable = std.math.big.int.Mutable;
......@@ -80,7 +81,7 @@ test "minUnsignedBits" {
8081 defer arena_state.deinit();
8182 const arena = arena_state.allocator();
8283
83 var comp = Compilation.init(std.testing.allocator, arena, std.testing.io, undefined, std.fs.cwd());
84 var comp = Compilation.init(std.testing.allocator, arena, std.testing.io, undefined, Io.Dir.cwd());
8485 defer comp.deinit();
8586 const target_query = try std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux-gnu" });
8687 comp.target = .fromZigTarget(try std.zig.system.resolveTargetQuery(std.testing.io, target_query));
......@@ -119,7 +120,7 @@ test "minSignedBits" {
119120 defer arena_state.deinit();
120121 const arena = arena_state.allocator();
121122
122 var comp = Compilation.init(std.testing.allocator, arena, std.testing.io, undefined, std.fs.cwd());
123 var comp = Compilation.init(std.testing.allocator, arena, std.testing.io, undefined, Io.Dir.cwd());
123124 defer comp.deinit();
124125 const target_query = try std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux-gnu" });
125126 comp.target = .fromZigTarget(try std.zig.system.resolveTargetQuery(std.testing.io, target_query));
......@@ -1080,7 +1081,7 @@ const NestedPrint = union(enum) {
10801081 },
10811082};
10821083
1083pub fn printPointer(offset: Value, base: []const u8, comp: *const Compilation, w: *std.Io.Writer) std.Io.Writer.Error!void {
1084pub fn printPointer(offset: Value, base: []const u8, comp: *const Compilation, w: *Io.Writer) Io.Writer.Error!void {
10841085 try w.writeByte('&');
10851086 try w.writeAll(base);
10861087 if (!offset.isZero(comp)) {
......@@ -1089,7 +1090,7 @@ pub fn printPointer(offset: Value, base: []const u8, comp: *const Compilation, w
10891090 }
10901091}
10911092
1092pub fn print(v: Value, qt: QualType, comp: *const Compilation, w: *std.Io.Writer) std.Io.Writer.Error!?NestedPrint {
1093pub fn print(v: Value, qt: QualType, comp: *const Compilation, w: *Io.Writer) Io.Writer.Error!?NestedPrint {
10931094 if (qt.is(comp, .bool)) {
10941095 try w.writeAll(if (v.isZero(comp)) "false" else "true");
10951096 return null;
......@@ -1116,7 +1117,7 @@ pub fn print(v: Value, qt: QualType, comp: *const Compilation, w: *std.Io.Writer
11161117 return null;
11171118}
11181119
1119pub fn printString(bytes: []const u8, qt: QualType, comp: *const Compilation, w: *std.Io.Writer) std.Io.Writer.Error!void {
1120pub fn printString(bytes: []const u8, qt: QualType, comp: *const Compilation, w: *Io.Writer) Io.Writer.Error!void {
11201121 const size: Compilation.CharUnitSize = @enumFromInt(qt.childType(comp).sizeof(comp));
11211122 const without_null = bytes[0 .. bytes.len - @intFromEnum(size)];
11221123 try w.writeByte('"');
lib/compiler/aro/main.zig+1-1
......@@ -59,7 +59,7 @@ pub fn main() u8 {
5959 } },
6060 };
6161
62 var comp = Compilation.initDefault(gpa, arena, io, &diagnostics, std.fs.cwd()) catch |er| switch (er) {
62 var comp = Compilation.initDefault(gpa, arena, io, &diagnostics, Io.Dir.cwd()) catch |er| switch (er) {
6363 error.OutOfMemory => {
6464 std.debug.print("out of memory\n", .{});
6565 if (fast_exit) process.exit(1);
lib/compiler/objcopy.zig+2-2
......@@ -152,7 +152,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
152152 defer threaded.deinit();
153153 const io = threaded.io();
154154
155 const input_file = fs.cwd().openFile(input, .{}) catch |err| fatal("failed to open {s}: {t}", .{ input, err });
155 const input_file = Io.Dir.cwd().openFile(input, .{}) catch |err| fatal("failed to open {s}: {t}", .{ input, err });
156156 defer input_file.close(io);
157157
158158 const stat = input_file.stat() catch |err| fatal("failed to stat {s}: {t}", .{ input, err });
......@@ -180,7 +180,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
180180
181181 const mode = if (out_fmt != .elf or only_keep_debug) Io.File.default_mode else stat.mode;
182182
183 var output_file = try fs.cwd().createFile(output, .{ .mode = mode });
183 var output_file = try Io.Dir.cwd().createFile(io, output, .{ .mode = mode });
184184 defer output_file.close(io);
185185
186186 var out = output_file.writer(&output_buffer);
lib/compiler/reduce.zig+3-3
......@@ -233,7 +233,7 @@ pub fn main() !void {
233233 }
234234 }
235235
236 try std.fs.cwd().writeFile(.{ .sub_path = root_source_file_path, .data = rendered.written() });
236 try Io.Dir.cwd().writeFile(.{ .sub_path = root_source_file_path, .data = rendered.written() });
237237 // std.debug.print("trying this code:\n{s}\n", .{rendered.items});
238238
239239 const interestingness = try runCheck(arena, interestingness_argv.items);
......@@ -274,7 +274,7 @@ pub fn main() !void {
274274 fixups.clearRetainingCapacity();
275275 rendered.clearRetainingCapacity();
276276 try tree.render(gpa, &rendered.writer, fixups);
277 try std.fs.cwd().writeFile(.{ .sub_path = root_source_file_path, .data = rendered.written() });
277 try Io.Dir.cwd().writeFile(.{ .sub_path = root_source_file_path, .data = rendered.written() });
278278
279279 return std.process.cleanExit();
280280 }
......@@ -398,7 +398,7 @@ fn transformationsToFixups(
398398}
399399
400400fn parse(gpa: Allocator, file_path: []const u8) !Ast {
401 const source_code = std.fs.cwd().readFileAllocOptions(
401 const source_code = Io.Dir.cwd().readFileAllocOptions(
402402 file_path,
403403 gpa,
404404 .limited(std.math.maxInt(u32)),
lib/compiler/resinator/cli.zig+1-1
......@@ -2003,7 +2003,7 @@ test "maybeAppendRC" {
20032003
20042004 // Create the file so that it's found. In this scenario, .rc should not get
20052005 // appended.
2006 var file = try tmp.dir.createFile("foo", .{});
2006 var file = try tmp.dir.createFile(io, "foo", .{});
20072007 file.close(io);
20082008 try options.maybeAppendRC(tmp.dir);
20092009 try std.testing.expectEqualStrings("foo", options.input_source.filename);
lib/compiler/resinator/compile.zig+2-2
......@@ -111,7 +111,7 @@ pub fn compile(allocator: Allocator, io: Io, source: []const u8, writer: *std.Io
111111 try search_dirs.append(allocator, .{ .dir = root_dir, .path = try allocator.dupe(u8, root_dir_path) });
112112 }
113113 }
114 // Re-open the passed in cwd since we want to be able to close it (std.fs.cwd() shouldn't be closed)
114 // Re-open the passed in cwd since we want to be able to close it (Io.Dir.cwd() shouldn't be closed)
115115 const cwd_dir = options.cwd.openDir(".", .{}) catch |err| {
116116 try options.diagnostics.append(.{
117117 .err = .failed_to_open_cwd,
......@@ -406,7 +406,7 @@ pub const Compiler = struct {
406406 // `/test.bin` relative to include paths and instead only treats it as
407407 // an absolute path.
408408 if (std.fs.path.isAbsolute(path)) {
409 const file = try utils.openFileNotDir(std.fs.cwd(), path, .{});
409 const file = try utils.openFileNotDir(Io.Dir.cwd(), path, .{});
410410 errdefer file.close(io);
411411
412412 if (self.dependencies) |dependencies| {
lib/compiler/resinator/main.zig+11-11
......@@ -67,7 +67,7 @@ pub fn main() !void {
6767 },
6868 else => |e| return e,
6969 };
70 try options.maybeAppendRC(std.fs.cwd());
70 try options.maybeAppendRC(Io.Dir.cwd());
7171
7272 if (!zig_integration) {
7373 // print any warnings/notes
......@@ -141,7 +141,7 @@ pub fn main() !void {
141141 if (!zig_integration) std.debug.unlockStderrWriter();
142142 }
143143
144 var comp = aro.Compilation.init(aro_arena, aro_arena, io, &diagnostics, std.fs.cwd());
144 var comp = aro.Compilation.init(aro_arena, aro_arena, io, &diagnostics, Io.Dir.cwd());
145145 defer comp.deinit();
146146
147147 var argv: std.ArrayList([]const u8) = .empty;
......@@ -196,7 +196,7 @@ pub fn main() !void {
196196 };
197197 },
198198 .filename => |input_filename| {
199 break :full_input std.fs.cwd().readFileAlloc(input_filename, gpa, .unlimited) catch |err| {
199 break :full_input Io.Dir.cwd().readFileAlloc(input_filename, gpa, .unlimited) catch |err| {
200200 try error_handler.emitMessage(gpa, .err, "unable to read input file path '{s}': {s}", .{ input_filename, @errorName(err) });
201201 std.process.exit(1);
202202 };
......@@ -212,7 +212,7 @@ pub fn main() !void {
212212 try output_file.writeAll(full_input);
213213 },
214214 .filename => |output_filename| {
215 try std.fs.cwd().writeFile(.{ .sub_path = output_filename, .data = full_input });
215 try Io.Dir.cwd().writeFile(.{ .sub_path = output_filename, .data = full_input });
216216 },
217217 }
218218 return;
......@@ -277,7 +277,7 @@ pub fn main() !void {
277277 const output_buffered_stream = res_stream_writer.interface();
278278
279279 compile(gpa, io, final_input, output_buffered_stream, .{
280 .cwd = std.fs.cwd(),
280 .cwd = Io.Dir.cwd(),
281281 .diagnostics = &diagnostics,
282282 .source_mappings = &mapping_results.mappings,
283283 .dependencies = maybe_dependencies,
......@@ -294,7 +294,7 @@ pub fn main() !void {
294294 .warn_instead_of_error_on_invalid_code_page = options.warn_instead_of_error_on_invalid_code_page,
295295 }) catch |err| switch (err) {
296296 error.ParseError, error.CompileError => {
297 try error_handler.emitDiagnostics(gpa, std.fs.cwd(), final_input, &diagnostics, mapping_results.mappings);
297 try error_handler.emitDiagnostics(gpa, Io.Dir.cwd(), final_input, &diagnostics, mapping_results.mappings);
298298 // Delete the output file on error
299299 res_stream.cleanupAfterError(io);
300300 std.process.exit(1);
......@@ -306,12 +306,12 @@ pub fn main() !void {
306306
307307 // print any warnings/notes
308308 if (!zig_integration) {
309 diagnostics.renderToStdErr(std.fs.cwd(), final_input, mapping_results.mappings);
309 diagnostics.renderToStdErr(Io.Dir.cwd(), final_input, mapping_results.mappings);
310310 }
311311
312312 // write the depfile
313313 if (options.depfile_path) |depfile_path| {
314 var depfile = std.fs.cwd().createFile(depfile_path, .{}) catch |err| {
314 var depfile = Io.Dir.cwd().createFile(io, depfile_path, .{}) catch |err| {
315315 try error_handler.emitMessage(gpa, .err, "unable to create depfile '{s}': {s}", .{ depfile_path, @errorName(err) });
316316 std.process.exit(1);
317317 };
......@@ -440,7 +440,7 @@ const IoStream = struct {
440440 // Delete the output file on error
441441 file.close(io);
442442 // Failing to delete is not really a big deal, so swallow any errors
443 std.fs.cwd().deleteFile(self.name) catch {};
443 Io.Dir.cwd().deleteFile(self.name) catch {};
444444 },
445445 .stdio, .memory, .closed => return,
446446 }
......@@ -457,8 +457,8 @@ const IoStream = struct {
457457 switch (source) {
458458 .filename => |filename| return .{
459459 .file = switch (io) {
460 .input => try openFileNotDir(std.fs.cwd(), filename, .{}),
461 .output => try std.fs.cwd().createFile(filename, .{}),
460 .input => try openFileNotDir(Io.Dir.cwd(), filename, .{}),
461 .output => try Io.Dir.cwd().createFile(io, filename, .{}),
462462 },
463463 },
464464 .stdio => |file| return .{ .stdio = file },
lib/compiler/std-docs.zig+1-1
......@@ -40,7 +40,7 @@ pub fn main() !void {
4040 const zig_exe_path = argv.next().?;
4141 const global_cache_path = argv.next().?;
4242
43 var lib_dir = try std.fs.cwd().openDir(zig_lib_directory, .{});
43 var lib_dir = try Io.Dir.cwd().openDir(zig_lib_directory, .{});
4444 defer lib_dir.close(io);
4545
4646 var listen_port: u16 = 0;
lib/compiler/translate-c/main.zig+4-4
......@@ -47,7 +47,7 @@ pub fn main() u8 {
4747 };
4848 defer diagnostics.deinit();
4949
50 var comp = aro.Compilation.initDefault(gpa, arena, io, &diagnostics, std.fs.cwd()) catch |err| switch (err) {
50 var comp = aro.Compilation.initDefault(gpa, arena, io, &diagnostics, Io.Dir.cwd()) catch |err| switch (err) {
5151 error.OutOfMemory => {
5252 std.debug.print("ran out of memory initializing C compilation\n", .{});
5353 if (fast_exit) process.exit(1);
......@@ -226,7 +226,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration
226226 const dep_file_name = try d.getDepFileName(source, out_buf[0..std.fs.max_name_bytes]);
227227
228228 const file = if (dep_file_name) |path|
229 d.comp.cwd.createFile(path, .{}) catch |er|
229 d.comp.cwd.createFile(io, path, .{}) catch |er|
230230 return d.fatal("unable to create dependency file '{s}': {s}", .{ path, aro.Driver.errorDescription(er) })
231231 else
232232 Io.File.stdout();
......@@ -253,10 +253,10 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration
253253 if (d.output_name) |path| blk: {
254254 if (std.mem.eql(u8, path, "-")) break :blk;
255255 if (std.fs.path.dirname(path)) |dirname| {
256 std.fs.cwd().makePath(dirname) catch |err|
256 Io.Dir.cwd().makePath(dirname) catch |err|
257257 return d.fatal("failed to create path to '{s}': {s}", .{ path, aro.Driver.errorDescription(err) });
258258 }
259 out_file = std.fs.cwd().createFile(path, .{}) catch |err| {
259 out_file = Io.Dir.cwd().createFile(io, path, .{}) catch |err| {
260260 return d.fatal("failed to create output file '{s}': {s}", .{ path, aro.Driver.errorDescription(err) });
261261 };
262262 close_out_file = true;
lib/std/Build.zig+5-5
......@@ -1702,13 +1702,13 @@ pub fn addCheckFile(
17021702pub fn truncateFile(b: *Build, dest_path: []const u8) (Io.Dir.MakeError || Io.Dir.StatFileError)!void {
17031703 const io = b.graph.io;
17041704 if (b.verbose) log.info("truncate {s}", .{dest_path});
1705 const cwd = fs.cwd();
1706 var src_file = cwd.createFile(dest_path, .{}) catch |err| switch (err) {
1705 const cwd = Io.Dir.cwd();
1706 var src_file = cwd.createFile(io, dest_path, .{}) catch |err| switch (err) {
17071707 error.FileNotFound => blk: {
17081708 if (fs.path.dirname(dest_path)) |dirname| {
17091709 try cwd.makePath(dirname);
17101710 }
1711 break :blk try cwd.createFile(dest_path, .{});
1711 break :blk try cwd.createFile(io, dest_path, .{});
17121712 },
17131713 else => |e| return e,
17141714 };
......@@ -1846,7 +1846,7 @@ pub fn runAllowFail(
18461846 };
18471847 errdefer b.allocator.free(stdout);
18481848
1849 const term = try child.wait();
1849 const term = try child.wait(io);
18501850 switch (term) {
18511851 .Exited => |code| {
18521852 if (code != 0) {
......@@ -2193,7 +2193,7 @@ fn dependencyInner(
21932193
21942194 const build_root: std.Build.Cache.Directory = .{
21952195 .path = build_root_string,
2196 .handle = fs.cwd().openDir(build_root_string, .{}) catch |err| {
2196 .handle = Io.Dir.cwd().openDir(build_root_string, .{}) catch |err| {
21972197 std.debug.print("unable to open '{s}': {s}\n", .{
21982198 build_root_string, @errorName(err),
21992199 });
lib/std/Build/Cache.zig+4-4
......@@ -508,7 +508,7 @@ pub const Manifest = struct {
508508 // and `want_shared_lock` is set, a shared lock might be sufficient, so we'll
509509 // open with a shared lock instead.
510510 while (true) {
511 if (self.cache.manifest_dir.createFile(&manifest_file_path, .{
511 if (self.cache.manifest_dir.createFile(io, &manifest_file_path, .{
512512 .read = true,
513513 .truncate = false,
514514 .lock = .exclusive,
......@@ -543,7 +543,7 @@ pub const Manifest = struct {
543543 return error.CacheCheckFailed;
544544 }
545545
546 if (self.cache.manifest_dir.createFile(&manifest_file_path, .{
546 if (self.cache.manifest_dir.createFile(io, &manifest_file_path, .{
547547 .read = true,
548548 .truncate = false,
549549 .lock = .exclusive,
......@@ -873,7 +873,7 @@ pub const Manifest = struct {
873873 if (man.want_refresh_timestamp) {
874874 man.want_refresh_timestamp = false;
875875
876 var file = man.cache.manifest_dir.createFile("timestamp", .{
876 var file = man.cache.manifest_dir.createFile(io, "timestamp", .{
877877 .read = true,
878878 .truncate = true,
879879 }) catch |err| switch (err) {
......@@ -1324,7 +1324,7 @@ fn hashFile(file: Io.File, bin_digest: *[Hasher.mac_length]u8) Io.File.PReadErro
13241324fn testGetCurrentFileTimestamp(io: Io, dir: Io.Dir) !Io.Timestamp {
13251325 const test_out_file = "test-filetimestamp.tmp";
13261326
1327 var file = try dir.createFile(test_out_file, .{
1327 var file = try dir.createFile(io, test_out_file, .{
13281328 .read = true,
13291329 .truncate = true,
13301330 });
lib/std/Build/Step.zig+9-8
......@@ -401,6 +401,9 @@ pub fn evalZigProcess(
401401 web_server: ?*Build.WebServer,
402402 gpa: Allocator,
403403) !?Path {
404 const b = s.owner;
405 const io = b.graph.io;
406
404407 // If an error occurs, it's happened in this command:
405408 assert(s.result_failed_command == null);
406409 s.result_failed_command = try allocPrintCmd(gpa, null, argv);
......@@ -411,7 +414,7 @@ pub fn evalZigProcess(
411414 const result = zigProcessUpdate(s, zp, watch, web_server, gpa) catch |err| switch (err) {
412415 error.BrokenPipe => {
413416 // Process restart required.
414 const term = zp.child.wait() catch |e| {
417 const term = zp.child.wait(io) catch |e| {
415418 return s.fail("unable to wait for {s}: {t}", .{ argv[0], e });
416419 };
417420 _ = term;
......@@ -427,7 +430,7 @@ pub fn evalZigProcess(
427430
428431 if (s.result_error_msgs.items.len > 0 and result == null) {
429432 // Crash detected.
430 const term = zp.child.wait() catch |e| {
433 const term = zp.child.wait(io) catch |e| {
431434 return s.fail("unable to wait for {s}: {t}", .{ argv[0], e });
432435 };
433436 s.result_peak_rss = zp.child.resource_usage_statistics.getMaxRss() orelse 0;
......@@ -439,9 +442,7 @@ pub fn evalZigProcess(
439442 return result;
440443 }
441444 assert(argv.len != 0);
442 const b = s.owner;
443445 const arena = b.allocator;
444 const io = b.graph.io;
445446
446447 try handleChildProcUnsupported(s);
447448 try handleVerbose(s.owner, null, argv);
......@@ -478,7 +479,7 @@ pub fn evalZigProcess(
478479 zp.child.stdin.?.close(io);
479480 zp.child.stdin = null;
480481
481 const term = zp.child.wait() catch |err| {
482 const term = zp.child.wait(io) catch |err| {
482483 return s.fail("unable to wait for {s}: {t}", .{ argv[0], err });
483484 };
484485 s.result_peak_rss = zp.child.resource_usage_statistics.getMaxRss() orelse 0;
......@@ -519,7 +520,7 @@ pub fn installFile(s: *Step, src_lazy_path: Build.LazyPath, dest_path: []const u
519520pub fn installDir(s: *Step, dest_path: []const u8) !Io.Dir.MakePathStatus {
520521 const b = s.owner;
521522 try handleVerbose(b, null, &.{ "install", "-d", dest_path });
522 return std.fs.cwd().makePathStatus(dest_path) catch |err|
523 return Io.Dir.cwd().makePathStatus(dest_path) catch |err|
523524 return s.fail("unable to create dir '{s}': {t}", .{ dest_path, err });
524525}
525526
......@@ -895,7 +896,7 @@ pub fn addWatchInput(step: *Step, lazy_file: Build.LazyPath) Allocator.Error!voi
895896 try addWatchInputFromPath(step, .{
896897 .root_dir = .{
897898 .path = null,
898 .handle = std.fs.cwd(),
899 .handle = Io.Dir.cwd(),
899900 },
900901 .sub_path = std.fs.path.dirname(path_string) orelse "",
901902 }, std.fs.path.basename(path_string));
......@@ -920,7 +921,7 @@ pub fn addDirectoryWatchInput(step: *Step, lazy_directory: Build.LazyPath) Alloc
920921 try addDirectoryWatchInputFromPath(step, .{
921922 .root_dir = .{
922923 .path = null,
923 .handle = std.fs.cwd(),
924 .handle = Io.Dir.cwd(),
924925 },
925926 .sub_path = path_string,
926927 });
lib/std/Build/Step/CheckFile.zig+3-1
......@@ -3,7 +3,9 @@
33//! TODO: generalize the code in std.testing.expectEqualStrings and make this
44//! CheckFile step produce those helpful diagnostics when there is not a match.
55const CheckFile = @This();
6
67const std = @import("std");
8const Io = std.Io;
79const Step = std.Build.Step;
810const fs = std.fs;
911const mem = std.mem;
......@@ -53,7 +55,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
5355 try step.singleUnchangingWatchInput(check_file.source);
5456
5557 const src_path = check_file.source.getPath2(b, step);
56 const contents = fs.cwd().readFileAlloc(src_path, b.allocator, .limited(check_file.max_bytes)) catch |err| {
58 const contents = Io.Dir.cwd().readFileAlloc(src_path, b.allocator, .limited(check_file.max_bytes)) catch |err| {
5759 return step.fail("unable to read '{s}': {s}", .{
5860 src_path, @errorName(err),
5961 });
lib/std/Build/Step/ConfigHeader.zig+5-3
......@@ -1,5 +1,7 @@
1const std = @import("std");
21const ConfigHeader = @This();
2
3const std = @import("std");
4const Io = std.Io;
35const Step = std.Build.Step;
46const Allocator = std.mem.Allocator;
57const Writer = std.Io.Writer;
......@@ -205,7 +207,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
205207 .autoconf_undef, .autoconf_at => |file_source| {
206208 try bw.writeAll(c_generated_line);
207209 const src_path = file_source.getPath2(b, step);
208 const contents = std.fs.cwd().readFileAlloc(src_path, arena, .limited(config_header.max_bytes)) catch |err| {
210 const contents = Io.Dir.cwd().readFileAlloc(src_path, arena, .limited(config_header.max_bytes)) catch |err| {
209211 return step.fail("unable to read autoconf input file '{s}': {s}", .{
210212 src_path, @errorName(err),
211213 });
......@@ -219,7 +221,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
219221 .cmake => |file_source| {
220222 try bw.writeAll(c_generated_line);
221223 const src_path = file_source.getPath2(b, step);
222 const contents = std.fs.cwd().readFileAlloc(src_path, arena, .limited(config_header.max_bytes)) catch |err| {
224 const contents = Io.Dir.cwd().readFileAlloc(src_path, arena, .limited(config_header.max_bytes)) catch |err| {
223225 return step.fail("unable to read cmake input file '{s}': {s}", .{
224226 src_path, @errorName(err),
225227 });
lib/std/Build/Step/Options.zig+8-7
......@@ -1,12 +1,13 @@
1const std = @import("std");
1const Options = @This();
22const builtin = @import("builtin");
3
4const std = @import("std");
5const Io = std.Io;
36const fs = std.fs;
47const Step = std.Build.Step;
58const GeneratedFile = std.Build.GeneratedFile;
69const LazyPath = std.Build.LazyPath;
710
8const Options = @This();
9
1011pub const base_id: Step.Id = .options;
1112
1213step: Step,
......@@ -542,11 +543,11 @@ test Options {
542543 .cache = .{
543544 .io = io,
544545 .gpa = arena.allocator(),
545 .manifest_dir = std.fs.cwd(),
546 .manifest_dir = Io.Dir.cwd(),
546547 },
547548 .zig_exe = "test",
548549 .env_map = std.process.EnvMap.init(arena.allocator()),
549 .global_cache_root = .{ .path = "test", .handle = std.fs.cwd() },
550 .global_cache_root = .{ .path = "test", .handle = Io.Dir.cwd() },
550551 .host = .{
551552 .query = .{},
552553 .result = try std.zig.system.resolveTargetQuery(io, .{}),
......@@ -557,8 +558,8 @@ test Options {
557558
558559 var builder = try std.Build.create(
559560 &graph,
560 .{ .path = "test", .handle = std.fs.cwd() },
561 .{ .path = "test", .handle = std.fs.cwd() },
561 .{ .path = "test", .handle = Io.Dir.cwd() },
562 .{ .path = "test", .handle = Io.Dir.cwd() },
562563 &.{},
563564 );
564565
lib/std/Build/Step/Run.zig+1-1
......@@ -1023,7 +1023,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
10231023
10241024 try runCommand(run, argv_list.items, has_side_effects, tmp_dir_path, options, null);
10251025
1026 const dep_file_dir = std.fs.cwd();
1026 const dep_file_dir = Io.Dir.cwd();
10271027 const dep_file_basename = dep_output_file.generated_file.getPath2(b, step);
10281028 if (has_side_effects)
10291029 try man.addDepFile(dep_file_dir, dep_file_basename)
lib/std/Build/Watch.zig+8-8
......@@ -122,7 +122,7 @@ const Os = switch (builtin.os.tag) {
122122 }) catch return error.NameTooLong;
123123 const stack_ptr: *std.os.linux.file_handle = @ptrCast(&file_handle_buffer);
124124 stack_ptr.handle_bytes = file_handle_buffer.len - @sizeOf(std.os.linux.file_handle);
125 try posix.name_to_handle_at(path.root_dir.handle.fd, adjusted_path, stack_ptr, mount_id, std.os.linux.AT.HANDLE_FID);
125 try posix.name_to_handle_at(path.root_dir.handle.handle, adjusted_path, stack_ptr, mount_id, std.os.linux.AT.HANDLE_FID);
126126 const stack_lfh: FileHandle = .{ .handle = stack_ptr };
127127 return stack_lfh.clone(gpa);
128128 }
......@@ -222,7 +222,7 @@ const Os = switch (builtin.os.tag) {
222222 posix.fanotify_mark(fan_fd, .{
223223 .ADD = true,
224224 .ONLYDIR = true,
225 }, fan_mask, path.root_dir.handle.fd, path.subPathOrDot()) catch |err| {
225 }, fan_mask, path.root_dir.handle.handle, path.subPathOrDot()) catch |err| {
226226 fatal("unable to watch {f}: {s}", .{ path, @errorName(err) });
227227 };
228228 }
......@@ -275,7 +275,7 @@ const Os = switch (builtin.os.tag) {
275275 posix.fanotify_mark(fan_fd, .{
276276 .REMOVE = true,
277277 .ONLYDIR = true,
278 }, fan_mask, path.root_dir.handle.fd, path.subPathOrDot()) catch |err| switch (err) {
278 }, fan_mask, path.root_dir.handle.handle, path.subPathOrDot()) catch |err| switch (err) {
279279 error.FileNotFound => {}, // Expected, harmless.
280280 else => |e| std.log.warn("unable to unwatch '{f}': {s}", .{ path, @errorName(e) }),
281281 };
......@@ -353,7 +353,7 @@ const Os = switch (builtin.os.tag) {
353353 // The following code is a drawn out NtCreateFile call. (mostly adapted from Io.Dir.makeOpenDirAccessMaskW)
354354 // It's necessary in order to get the specific flags that are required when calling ReadDirectoryChangesW.
355355 var dir_handle: windows.HANDLE = undefined;
356 const root_fd = path.root_dir.handle.fd;
356 const root_fd = path.root_dir.handle.handle;
357357 const sub_path = path.subPathOrDot();
358358 const sub_path_w = try windows.sliceToPrefixedFileW(root_fd, sub_path);
359359 const path_len_bytes = std.math.cast(u16, sub_path_w.len * 2) orelse return error.NameTooLong;
......@@ -681,9 +681,9 @@ const Os = switch (builtin.os.tag) {
681681 if (!gop.found_existing) {
682682 const skip_open_dir = path.sub_path.len == 0;
683683 const dir_fd = if (skip_open_dir)
684 path.root_dir.handle.fd
684 path.root_dir.handle.handle
685685 else
686 posix.openat(path.root_dir.handle.fd, path.sub_path, dir_open_flags, 0) catch |err| {
686 posix.openat(path.root_dir.handle.handle, path.sub_path, dir_open_flags, 0) catch |err| {
687687 fatal("failed to open directory {f}: {s}", .{ path, @errorName(err) });
688688 };
689689 // Empirically the dir has to stay open or else no events are triggered.
......@@ -750,7 +750,7 @@ const Os = switch (builtin.os.tag) {
750750 // to access that data via the dir_fd field.
751751 const path = w.dir_table.keys()[i];
752752 const dir_fd = if (path.sub_path.len == 0)
753 path.root_dir.handle.fd
753 path.root_dir.handle.handle
754754 else
755755 handles.items(.dir_fd)[i];
756756 assert(dir_fd != -1);
......@@ -761,7 +761,7 @@ const Os = switch (builtin.os.tag) {
761761 const last_dir_fd = fd: {
762762 const last_path = w.dir_table.keys()[handles.len - 1];
763763 const last_dir_fd = if (last_path.sub_path.len == 0)
764 last_path.root_dir.handle.fd
764 last_path.root_dir.handle.handle
765765 else
766766 handles.items(.dir_fd)[handles.len - 1];
767767 assert(last_dir_fd != -1);
lib/std/Io/File.zig+8
......@@ -527,6 +527,14 @@ pub fn writerStreaming(file: File, io: Io, buffer: []u8) Writer {
527527 return .initStreaming(file, io, buffer);
528528}
529529
530/// Equivalent to creating a streaming writer, writing `bytes`, and then flushing.
531pub fn writeStreamingAll(file: File, io: Io, bytes: []const u8) Writer.Error!void {
532 var index: usize = 0;
533 while (index < bytes.len) {
534 index += try io.vtable.fileWriteStreaming(io.userdata, file, &.{}, &.{bytes[index..]}, 1);
535 }
536}
537
530538pub const LockError = error{
531539 SystemResources,
532540 FileLocksUnsupported,
lib/std/Io/Threaded.zig+3-6
......@@ -2361,7 +2361,7 @@ fn dirCreateFilePosix(
23612361 .NFILE => return error.SystemFdQuotaExceeded,
23622362 .NODEV => return error.NoDevice,
23632363 .NOENT => return error.FileNotFound,
2364 .SRCH => return error.ProcessNotFound,
2364 .SRCH => return error.FileNotFound, // Linux when accessing procfs.
23652365 .NOMEM => return error.SystemResources,
23662366 .NOSPC => return error.NoSpaceLeft,
23672367 .NOTDIR => return error.NotDir,
......@@ -2670,7 +2670,7 @@ fn dirOpenFilePosix(
26702670 .NFILE => return error.SystemFdQuotaExceeded,
26712671 .NODEV => return error.NoDevice,
26722672 .NOENT => return error.FileNotFound,
2673 .SRCH => return error.ProcessNotFound,
2673 .SRCH => return error.FileNotFound, // Linux when opening procfs files.
26742674 .NOMEM => return error.SystemResources,
26752675 .NOSPC => return error.NoSpaceLeft,
26762676 .NOTDIR => return error.NotDir,
......@@ -3287,7 +3287,7 @@ fn dirRealPathPosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, out_b
32873287 .NFILE => return error.SystemFdQuotaExceeded,
32883288 .NODEV => return error.NoDevice,
32893289 .NOENT => return error.FileNotFound,
3290 .SRCH => return error.ProcessNotFound,
3290 .SRCH => return error.FileNotFound, // Linux when accessing procfs.
32913291 .NOMEM => return error.SystemResources,
32923292 .NOSPC => return error.NoSpaceLeft,
32933293 .NOTDIR => return error.NotDir,
......@@ -5548,7 +5548,6 @@ fn fileReadStreamingPosix(userdata: ?*anyopaque, file: File, data: [][]u8) File.
55485548 switch (e) {
55495549 .INVAL => |err| return errnoBug(err),
55505550 .FAULT => |err| return errnoBug(err),
5551 .SRCH => return error.ProcessNotFound,
55525551 .AGAIN => return error.WouldBlock,
55535552 .BADF => |err| {
55545553 if (native_os == .wasi) return error.NotOpenForReading; // File operation on directory.
......@@ -5672,7 +5671,6 @@ fn fileReadPositionalPosix(userdata: ?*anyopaque, file: File, data: [][]u8, offs
56725671 switch (e) {
56735672 .INVAL => |err| return errnoBug(err),
56745673 .FAULT => |err| return errnoBug(err),
5675 .SRCH => return error.ProcessNotFound,
56765674 .AGAIN => return error.WouldBlock,
56775675 .BADF => |err| {
56785676 if (native_os == .wasi) return error.NotOpenForReading; // File operation on directory.
......@@ -6312,7 +6310,6 @@ fn fileWriteStreaming(
63126310 switch (e) {
63136311 .INVAL => return error.InvalidArgument,
63146312 .FAULT => |err| return errnoBug(err),
6315 .SRCH => return error.ProcessNotFound,
63166313 .AGAIN => return error.WouldBlock,
63176314 .BADF => return error.NotOpenForWriting, // Can be a race condition.
63186315 .DESTADDRREQ => |err| return errnoBug(err), // `connect` was never called.
lib/std/Io/Writer.zig+3-3
......@@ -2835,7 +2835,7 @@ test "discarding sendFile" {
28352835 var tmp_dir = testing.tmpDir(.{});
28362836 defer tmp_dir.cleanup();
28372837
2838 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });
2838 const file = try tmp_dir.dir.createFile(io, "input.txt", .{ .read = true });
28392839 defer file.close(io);
28402840 var r_buffer: [256]u8 = undefined;
28412841 var file_writer: File.Writer = .init(file, &r_buffer);
......@@ -2857,7 +2857,7 @@ test "allocating sendFile" {
28572857 var tmp_dir = testing.tmpDir(.{});
28582858 defer tmp_dir.cleanup();
28592859
2860 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });
2860 const file = try tmp_dir.dir.createFile(io, "input.txt", .{ .read = true });
28612861 defer file.close(io);
28622862 var r_buffer: [2]u8 = undefined;
28632863 var file_writer: File.Writer = .init(file, &r_buffer);
......@@ -2881,7 +2881,7 @@ test sendFileReading {
28812881 var tmp_dir = testing.tmpDir(.{});
28822882 defer tmp_dir.cleanup();
28832883
2884 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });
2884 const file = try tmp_dir.dir.createFile(io, "input.txt", .{ .read = true });
28852885 defer file.close(io);
28862886 var r_buffer: [2]u8 = undefined;
28872887 var file_writer: File.Writer = .init(file, &r_buffer);
lib/std/Io/net/test.zig+1-1
......@@ -278,7 +278,7 @@ test "listen on a unix socket, send bytes, receive bytes" {
278278 defer testing.allocator.free(socket_path);
279279
280280 const socket_addr = try net.UnixAddress.init(socket_path);
281 defer std.fs.cwd().deleteFile(socket_path) catch {};
281 defer Io.Dir.cwd().deleteFile(socket_path) catch {};
282282
283283 var server = try socket_addr.listen(io, .{});
284284 defer server.socket.close(io);
lib/std/Io/test.zig+5-5
......@@ -27,7 +27,7 @@ test "write a file, read it, then delete it" {
2727 random.bytes(data[0..]);
2828 const tmp_file_name = "temp_test_file.txt";
2929 {
30 var file = try tmp.dir.createFile(tmp_file_name, .{});
30 var file = try tmp.dir.createFile(io, tmp_file_name, .{});
3131 defer file.close(io);
3232
3333 var file_writer = file.writer(&.{});
......@@ -40,7 +40,7 @@ test "write a file, read it, then delete it" {
4040
4141 {
4242 // Make sure the exclusive flag is honored.
43 try expectError(File.OpenError.PathAlreadyExists, tmp.dir.createFile(tmp_file_name, .{ .exclusive = true }));
43 try expectError(File.OpenError.PathAlreadyExists, tmp.dir.createFile(io, tmp_file_name, .{ .exclusive = true }));
4444 }
4545
4646 {
......@@ -70,7 +70,7 @@ test "File seek ops" {
7070 const io = testing.io;
7171
7272 const tmp_file_name = "temp_test_file.txt";
73 var file = try tmp.dir.createFile(tmp_file_name, .{});
73 var file = try tmp.dir.createFile(io, tmp_file_name, .{});
7474 defer file.close(io);
7575
7676 try file.writeAll(&([_]u8{0x55} ** 8192));
......@@ -96,7 +96,7 @@ test "setEndPos" {
9696 defer tmp.cleanup();
9797
9898 const tmp_file_name = "temp_test_file.txt";
99 var file = try tmp.dir.createFile(tmp_file_name, .{});
99 var file = try tmp.dir.createFile(io, tmp_file_name, .{});
100100 defer file.close(io);
101101
102102 // Verify that the file size changes and the file offset is not moved
......@@ -121,7 +121,7 @@ test "updateTimes" {
121121 defer tmp.cleanup();
122122
123123 const tmp_file_name = "just_a_temporary_file.txt";
124 var file = try tmp.dir.createFile(tmp_file_name, .{ .read = true });
124 var file = try tmp.dir.createFile(io, tmp_file_name, .{ .read = true });
125125 defer file.close(io);
126126
127127 const stat_old = try file.stat();
lib/std/Thread.zig+2-2
......@@ -208,7 +208,7 @@ pub fn setName(self: Thread, io: Io, name: []const u8) SetNameError!void {
208208 var buf: [32]u8 = undefined;
209209 const path = try std.fmt.bufPrint(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()});
210210
211 const file = try std.fs.cwd().openFile(io, path, .{ .mode = .write_only });
211 const file = try Io.Dir.cwd().openFile(io, path, .{ .mode = .write_only });
212212 defer file.close(io);
213213
214214 try file.writeAll(name);
......@@ -325,7 +325,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
325325 var threaded: std.Io.Threaded = .init_single_threaded;
326326 const io = threaded.ioBasic();
327327
328 const file = try std.fs.cwd().openFile(io, path, .{});
328 const file = try Io.Dir.cwd().openFile(io, path, .{});
329329 defer file.close(io);
330330
331331 var file_reader = file.readerStreaming(io, &.{});
lib/std/crypto/Certificate/Bundle/macos.zig+1-1
......@@ -19,7 +19,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanM
1919
2020 _ = io; // TODO migrate file system to use std.Io
2121 for (keychain_paths) |keychain_path| {
22 const bytes = std.fs.cwd().readFileAlloc(keychain_path, gpa, .limited(std.math.maxInt(u32))) catch |err| switch (err) {
22 const bytes = Io.Dir.cwd().readFileAlloc(keychain_path, gpa, .limited(std.math.maxInt(u32))) catch |err| switch (err) {
2323 error.StreamTooLong => return error.FileTooBig,
2424 else => |e| return e,
2525 };
lib/std/crypto/codecs/asn1/test.zig+2-2
......@@ -73,8 +73,8 @@ test AllTypes {
7373 try std.testing.expectEqualSlices(u8, encoded, buf);
7474
7575 // Use this to update test file.
76 // const dir = try std.fs.cwd().openDir("lib/std/crypto/asn1", .{});
77 // var file = try dir.createFile(path, .{});
76 // const dir = try Io.Dir.cwd().openDir("lib/std/crypto/asn1", .{});
77 // var file = try dir.createFile(io, path, .{});
7878 // defer file.close(io);
7979 // try file.writeAll(buf);
8080}
lib/std/debug.zig+10-10
......@@ -60,7 +60,7 @@ pub const cpu_context = @import("debug/cpu_context.zig");
6060/// };
6161/// /// Only required if `can_unwind == true`. Unwinds a single stack frame, returning the frame's
6262/// /// return address, or 0 if the end of the stack has been reached.
63/// pub fn unwindFrame(si: *SelfInfo, gpa: Allocator, context: *UnwindContext) SelfInfoError!usize;
63/// pub fn unwindFrame(si: *SelfInfo, gpa: Allocator, io: Io, context: *UnwindContext) SelfInfoError!usize;
6464/// ```
6565pub const SelfInfo = if (@hasDecl(root, "debug") and @hasDecl(root.debug, "SelfInfo"))
6666 root.debug.SelfInfo
......@@ -558,9 +558,9 @@ pub fn defaultPanic(
558558 stderr.print("{s}\n", .{msg}) catch break :trace;
559559
560560 if (@errorReturnTrace()) |t| if (t.index > 0) {
561 stderr.writeAll("error return context:\n") catch break :trace;
561 stderr.writeStreamingAll("error return context:\n") catch break :trace;
562562 writeStackTrace(t, stderr, tty_config) catch break :trace;
563 stderr.writeAll("\nstack trace:\n") catch break :trace;
563 stderr.writeStreamingAll("\nstack trace:\n") catch break :trace;
564564 };
565565 writeCurrentStackTrace(.{
566566 .first_address = first_trace_addr orelse @returnAddress(),
......@@ -575,7 +575,7 @@ pub fn defaultPanic(
575575 // A panic happened while trying to print a previous panic message.
576576 // We're still holding the mutex but that's fine as we're going to
577577 // call abort().
578 File.stderr().writeAll("aborting due to recursive panic\n") catch {};
578 File.stderr().writeStreamingAll("aborting due to recursive panic\n") catch {};
579579 },
580580 else => {}, // Panicked while printing the recursive panic message.
581581 }
......@@ -960,7 +960,7 @@ const StackIterator = union(enum) {
960960 },
961961 };
962962
963 fn next(it: *StackIterator) Result {
963 fn next(it: *StackIterator, io: Io) Result {
964964 switch (it.*) {
965965 .ctx_first => |context_ptr| {
966966 // After the first frame, start actually unwinding.
......@@ -976,7 +976,7 @@ const StackIterator = union(enum) {
976976 .di => |*unwind_context| {
977977 const di = getSelfDebugInfo() catch unreachable;
978978 const di_gpa = getDebugInfoAllocator();
979 const ret_addr = di.unwindFrame(di_gpa, unwind_context) catch |err| {
979 const ret_addr = di.unwindFrame(di_gpa, io, unwind_context) catch |err| {
980980 const pc = unwind_context.pc;
981981 const fp = unwind_context.getFp();
982982 it.* = .{ .fp = fp };
......@@ -1297,7 +1297,7 @@ test printLineFromFile {
12971297 aw.clearRetainingCapacity();
12981298 }
12991299 {
1300 const file = try test_dir.dir.createFile("line_overlaps_page_boundary.zig", .{});
1300 const file = try test_dir.dir.createFile(io, "line_overlaps_page_boundary.zig", .{});
13011301 defer file.close(io);
13021302 const path = try fs.path.join(gpa, &.{ test_dir_path, "line_overlaps_page_boundary.zig" });
13031303 defer gpa.free(path);
......@@ -1316,7 +1316,7 @@ test printLineFromFile {
13161316 aw.clearRetainingCapacity();
13171317 }
13181318 {
1319 const file = try test_dir.dir.createFile("file_ends_on_page_boundary.zig", .{});
1319 const file = try test_dir.dir.createFile(io, "file_ends_on_page_boundary.zig", .{});
13201320 defer file.close(io);
13211321 const path = try fs.path.join(gpa, &.{ test_dir_path, "file_ends_on_page_boundary.zig" });
13221322 defer gpa.free(path);
......@@ -1330,7 +1330,7 @@ test printLineFromFile {
13301330 aw.clearRetainingCapacity();
13311331 }
13321332 {
1333 const file = try test_dir.dir.createFile("very_long_first_line_spanning_multiple_pages.zig", .{});
1333 const file = try test_dir.dir.createFile(io, "very_long_first_line_spanning_multiple_pages.zig", .{});
13341334 defer file.close(io);
13351335 const path = try fs.path.join(gpa, &.{ test_dir_path, "very_long_first_line_spanning_multiple_pages.zig" });
13361336 defer gpa.free(path);
......@@ -1356,7 +1356,7 @@ test printLineFromFile {
13561356 aw.clearRetainingCapacity();
13571357 }
13581358 {
1359 const file = try test_dir.dir.createFile("file_of_newlines.zig", .{});
1359 const file = try test_dir.dir.createFile(io, "file_of_newlines.zig", .{});
13601360 defer file.close(io);
13611361 const path = try fs.path.join(gpa, &.{ test_dir_path, "file_of_newlines.zig" });
13621362 defer gpa.free(path);
lib/std/debug/ElfFile.zig+1-1
......@@ -375,7 +375,7 @@ fn loadSeparateDebugFile(
375375 args: anytype,
376376) Allocator.Error!?[]align(std.heap.page_size_min) const u8 {
377377 const path = try std.fmt.allocPrint(arena, fmt, args);
378 const elf_file = std.fs.cwd().openFile(io, path, .{}) catch return null;
378 const elf_file = Io.Dir.cwd().openFile(io, path, .{}) catch return null;
379379 defer elf_file.close(io);
380380
381381 const result = loadInner(arena, elf_file, opt_crc) catch |err| switch (err) {
lib/std/debug/MachOFile.zig+1-1
......@@ -512,7 +512,7 @@ fn loadOFile(gpa: Allocator, io: Io, o_file_name: []const u8) !OFile {
512512
513513/// Uses `mmap` to map the file at `path` into memory.
514514fn mapDebugInfoFile(io: Io, path: []const u8) ![]align(std.heap.page_size_min) const u8 {
515 const file = std.fs.cwd().openFile(io, path, .{}) catch |err| switch (err) {
515 const file = Io.Dir.cwd().openFile(io, path, .{}) catch |err| switch (err) {
516516 error.FileNotFound => return error.MissingDebugInfo,
517517 else => return error.ReadFailed,
518518 };
lib/std/debug/SelfInfo/Elf.zig+9-10
......@@ -29,13 +29,12 @@ pub fn deinit(si: *SelfInfo, gpa: Allocator) void {
2929}
3030
3131pub fn getSymbol(si: *SelfInfo, gpa: Allocator, io: Io, address: usize) Error!std.debug.Symbol {
32 _ = io;
3332 const module = try si.findModule(gpa, address, .exclusive);
3433 defer si.rwlock.unlock();
3534
3635 const vaddr = address - module.load_offset;
3736
38 const loaded_elf = try module.getLoadedElf(gpa);
37 const loaded_elf = try module.getLoadedElf(gpa, io);
3938 if (loaded_elf.file.dwarf) |*dwarf| {
4039 if (!loaded_elf.scanned_dwarf) {
4140 dwarf.open(gpa, native_endian) catch |err| switch (err) {
......@@ -180,7 +179,7 @@ comptime {
180179 }
181180}
182181pub const UnwindContext = Dwarf.SelfUnwinder;
183pub fn unwindFrame(si: *SelfInfo, gpa: Allocator, context: *UnwindContext) Error!usize {
182pub fn unwindFrame(si: *SelfInfo, gpa: Allocator, io: Io, context: *UnwindContext) Error!usize {
184183 comptime assert(can_unwind);
185184
186185 {
......@@ -201,7 +200,7 @@ pub fn unwindFrame(si: *SelfInfo, gpa: Allocator, context: *UnwindContext) Error
201200 @memset(si.unwind_cache.?, .empty);
202201 }
203202
204 const unwind_sections = try module.getUnwindSections(gpa);
203 const unwind_sections = try module.getUnwindSections(gpa, io);
205204 for (unwind_sections) |*unwind| {
206205 if (context.computeRules(gpa, unwind, module.load_offset, null)) |entry| {
207206 entry.populate(si.unwind_cache.?);
......@@ -261,12 +260,12 @@ const Module = struct {
261260 };
262261
263262 /// Assumes we already hold an exclusive lock.
264 fn getUnwindSections(mod: *Module, gpa: Allocator) Error![]Dwarf.Unwind {
265 if (mod.unwind == null) mod.unwind = loadUnwindSections(mod, gpa);
263 fn getUnwindSections(mod: *Module, gpa: Allocator, io: Io) Error![]Dwarf.Unwind {
264 if (mod.unwind == null) mod.unwind = loadUnwindSections(mod, gpa, io);
266265 const us = &(mod.unwind.? catch |err| return err);
267266 return us.buf[0..us.len];
268267 }
269 fn loadUnwindSections(mod: *Module, gpa: Allocator) Error!UnwindSections {
268 fn loadUnwindSections(mod: *Module, gpa: Allocator, io: Io) Error!UnwindSections {
270269 var us: UnwindSections = .{
271270 .buf = undefined,
272271 .len = 0,
......@@ -284,7 +283,7 @@ const Module = struct {
284283 } else {
285284 // There is no `.eh_frame_hdr` section. There may still be an `.eh_frame` or `.debug_frame`
286285 // section, but we'll have to load the binary to get at it.
287 const loaded = try mod.getLoadedElf(gpa);
286 const loaded = try mod.getLoadedElf(gpa, io);
288287 // If both are present, we can't just pick one -- the info could be split between them.
289288 // `.debug_frame` is likely to be the more complete section, so we'll prioritize that one.
290289 if (loaded.file.debug_frame) |*debug_frame| {
......@@ -325,7 +324,7 @@ const Module = struct {
325324 }
326325 fn loadElf(mod: *Module, gpa: Allocator, io: Io) Error!LoadedElf {
327326 const load_result = if (mod.name.len > 0) res: {
328 var file = std.fs.cwd().openFile(io, mod.name, .{}) catch return error.MissingDebugInfo;
327 var file = Io.Dir.cwd().openFile(io, mod.name, .{}) catch return error.MissingDebugInfo;
329328 defer file.close(io);
330329 break :res std.debug.ElfFile.load(gpa, file, mod.build_id, &.native(mod.name));
331330 } else res: {
......@@ -334,7 +333,7 @@ const Module = struct {
334333 else => return error.ReadFailed,
335334 };
336335 defer gpa.free(path);
337 var file = std.fs.cwd().openFile(io, path, .{}) catch return error.MissingDebugInfo;
336 var file = Io.Dir.cwd().openFile(io, path, .{}) catch return error.MissingDebugInfo;
338337 defer file.close(io);
339338 break :res std.debug.ElfFile.load(gpa, file, mod.build_id, &.native(path));
340339 };
lib/std/debug/SelfInfo/MachO.zig+1-1
......@@ -616,7 +616,7 @@ test {
616616
617617/// Uses `mmap` to map the file at `path` into memory.
618618fn mapDebugInfoFile(io: Io, path: []const u8) ![]align(std.heap.page_size_min) const u8 {
619 const file = std.fs.cwd().openFile(io, path, .{}) catch |err| switch (err) {
619 const file = Io.Dir.cwd().openFile(io, path, .{}) catch |err| switch (err) {
620620 error.FileNotFound => return error.MissingDebugInfo,
621621 else => return error.ReadFailed,
622622 };
lib/std/debug/SelfInfo/Windows.zig+2-2
......@@ -432,7 +432,7 @@ const Module = struct {
432432 break :pdb null;
433433 };
434434 const pdb_file_open_result = if (fs.path.isAbsolute(path)) res: {
435 break :res std.fs.cwd().openFile(io, path, .{});
435 break :res Io.Dir.cwd().openFile(io, path, .{});
436436 } else res: {
437437 const self_dir = std.process.executableDirPathAlloc(io, gpa) catch |err| switch (err) {
438438 error.OutOfMemory, error.Unexpected => |e| return e,
......@@ -441,7 +441,7 @@ const Module = struct {
441441 defer gpa.free(self_dir);
442442 const abs_path = try fs.path.join(gpa, &.{ self_dir, path });
443443 defer gpa.free(abs_path);
444 break :res std.fs.cwd().openFile(io, abs_path, .{});
444 break :res Io.Dir.cwd().openFile(io, abs_path, .{});
445445 };
446446 const pdb_file = pdb_file_open_result catch |err| switch (err) {
447447 error.FileNotFound, error.IsDir => break :pdb null,
lib/std/dynamic_library.zig+4-4
......@@ -160,7 +160,7 @@ pub const ElfDynLib = struct {
160160 fn openPath(path: []const u8, io: Io) !Io.Dir {
161161 if (path.len == 0) return error.NotDir;
162162 var parts = std.mem.tokenizeScalar(u8, path, '/');
163 var parent = if (path[0] == '/') try std.fs.cwd().openDir("/", .{}) else std.fs.cwd();
163 var parent = if (path[0] == '/') try Io.Dir.cwd().openDir("/", .{}) else Io.Dir.cwd();
164164 while (parts.next()) |part| {
165165 const child = try parent.openDir(part, .{});
166166 parent.close(io);
......@@ -174,7 +174,7 @@ pub const ElfDynLib = struct {
174174 while (paths.next()) |p| {
175175 var dir = openPath(p) catch continue;
176176 defer dir.close(io);
177 const fd = posix.openat(dir.fd, file_name, .{
177 const fd = posix.openat(dir.handle, file_name, .{
178178 .ACCMODE = .RDONLY,
179179 .CLOEXEC = true,
180180 }, 0) catch continue;
......@@ -184,9 +184,9 @@ pub const ElfDynLib = struct {
184184 }
185185
186186 fn resolveFromParent(io: Io, dir_path: []const u8, file_name: []const u8) ?posix.fd_t {
187 var dir = std.fs.cwd().openDir(dir_path, .{}) catch return null;
187 var dir = Io.Dir.cwd().openDir(dir_path, .{}) catch return null;
188188 defer dir.close(io);
189 return posix.openat(dir.fd, file_name, .{
189 return posix.openat(dir.handle, file_name, .{
190190 .ACCMODE = .RDONLY,
191191 .CLOEXEC = true,
192192 }, 0) catch null;
lib/std/fs/test.zig+54-62
......@@ -46,7 +46,7 @@ const PathType = enum {
4646 // The final path may not actually exist which would cause realpath to fail.
4747 // So instead, we get the path of the dir and join it with the relative path.
4848 var fd_path_buf: [fs.max_path_bytes]u8 = undefined;
49 const dir_path = try std.os.getFdPath(dir.fd, &fd_path_buf);
49 const dir_path = try std.os.getFdPath(dir.handle, &fd_path_buf);
5050 return fs.path.joinZ(allocator, &.{ dir_path, relative_path });
5151 }
5252 }.transform,
......@@ -55,7 +55,7 @@ const PathType = enum {
5555 // Any drive absolute path (C:\foo) can be converted into a UNC path by
5656 // using '127.0.0.1' as the server name and '<drive letter>$' as the share name.
5757 var fd_path_buf: [fs.max_path_bytes]u8 = undefined;
58 const dir_path = try std.os.getFdPath(dir.fd, &fd_path_buf);
58 const dir_path = try std.os.getFdPath(dir.handle, &fd_path_buf);
5959 const windows_path_type = windows.getWin32PathType(u8, dir_path);
6060 switch (windows_path_type) {
6161 .unc_absolute => return fs.path.joinZ(allocator, &.{ dir_path, relative_path }),
......@@ -256,7 +256,7 @@ fn testReadLinkW(allocator: mem.Allocator, dir: Dir, target_path: []const u8, sy
256256 const target_path_w = try std.unicode.wtf8ToWtf16LeAlloc(allocator, target_path);
257257 defer allocator.free(target_path_w);
258258 // Calling the W functions directly requires the path to be NT-prefixed
259 const symlink_path_w = try std.os.windows.sliceToPrefixedFileW(dir.fd, symlink_path);
259 const symlink_path_w = try std.os.windows.sliceToPrefixedFileW(dir.handle, symlink_path);
260260 const wtf16_buffer = try allocator.alloc(u16, target_path_w.len);
261261 defer allocator.free(wtf16_buffer);
262262 const actual = try dir.readLinkW(symlink_path_w.span(), wtf16_buffer);
......@@ -288,9 +288,11 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {
288288
289289 var symlink: Dir = switch (builtin.target.os.tag) {
290290 .windows => windows_symlink: {
291 const sub_path_w = try windows.cStrToPrefixedFileW(ctx.dir.fd, "symlink");
291 const sub_path_w = try windows.cStrToPrefixedFileW(ctx.dir.handle, "symlink");
292292
293 var handle: windows.HANDLE = undefined;
293 var result: Dir = .{
294 .handle = undefined,
295 };
294296
295297 const path_len_bytes = @as(u16, @intCast(sub_path_w.span().len * 2));
296298 var nt_name = windows.UNICODE_STRING{
......@@ -300,26 +302,16 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {
300302 };
301303 var attr: windows.OBJECT_ATTRIBUTES = .{
302304 .Length = @sizeOf(windows.OBJECT_ATTRIBUTES),
303 .RootDirectory = if (fs.path.isAbsoluteWindowsW(sub_path_w.span())) null else ctx.dir.fd,
304 .Attributes = .{},
305 .RootDirectory = if (fs.path.isAbsoluteWindowsW(sub_path_w.span())) null else ctx.dir.handle,
306 .Attributes = 0,
305307 .ObjectName = &nt_name,
306308 .SecurityDescriptor = null,
307309 .SecurityQualityOfService = null,
308310 };
309311 var io_status_block: windows.IO_STATUS_BLOCK = undefined;
310312 const rc = windows.ntdll.NtCreateFile(
311 &handle,
312 .{
313 .SPECIFIC = .{ .FILE_DIRECTORY = .{
314 .READ_EA = true,
315 .TRAVERSE = true,
316 .READ_ATTRIBUTES = true,
317 } },
318 .STANDARD = .{
319 .RIGHTS = .READ,
320 .SYNCHRONIZE = true,
321 },
322 },
313 &result.handle,
314 windows.STANDARD_RIGHTS_READ | windows.FILE_READ_ATTRIBUTES | windows.FILE_READ_EA | windows.SYNCHRONIZE | windows.FILE_TRAVERSE,
323315 &attr,
324316 &io_status_block,
325317 null,
......@@ -337,7 +329,7 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {
337329 );
338330
339331 switch (rc) {
340 .SUCCESS => break :windows_symlink .{ .fd = handle },
332 .SUCCESS => break :windows_symlink .{ .fd = result.handle },
341333 else => return windows.unexpectedStatus(rc),
342334 }
343335 },
......@@ -351,8 +343,8 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {
351343 .ACCMODE = .RDONLY,
352344 .CLOEXEC = true,
353345 };
354 const fd = try posix.openatZ(ctx.dir.fd, &sub_path_c, flags, 0);
355 break :linux_symlink Dir{ .fd = fd };
346 const fd = try posix.openatZ(ctx.dir.handle, &sub_path_c, flags, 0);
347 break :linux_symlink .{ .handle = fd };
356348 },
357349 else => unreachable,
358350 };
......@@ -456,7 +448,7 @@ test "openDirAbsolute" {
456448test "openDir cwd parent '..'" {
457449 const io = testing.io;
458450
459 var dir = fs.cwd().openDir("..", .{}) catch |err| {
451 var dir = Io.Dir.cwd().openDir("..", .{}) catch |err| {
460452 if (native_os == .wasi and err == error.PermissionDenied) {
461453 return; // This is okay. WASI disallows escaping from the fs sandbox
462454 }
......@@ -534,7 +526,7 @@ test "Dir.Iterator" {
534526 defer tmp_dir.cleanup();
535527
536528 // First, create a couple of entries to iterate over.
537 const file = try tmp_dir.dir.createFile("some_file", .{});
529 const file = try tmp_dir.dir.createFile(io, "some_file", .{});
538530 file.close(io);
539531
540532 try tmp_dir.dir.makeDir("some_dir");
......@@ -570,7 +562,7 @@ test "Dir.Iterator many entries" {
570562 var buf: [4]u8 = undefined; // Enough to store "1024".
571563 while (i < num) : (i += 1) {
572564 const name = try std.fmt.bufPrint(&buf, "{}", .{i});
573 const file = try tmp_dir.dir.createFile(name, .{});
565 const file = try tmp_dir.dir.createFile(io, name, .{});
574566 file.close(io);
575567 }
576568
......@@ -603,7 +595,7 @@ test "Dir.Iterator twice" {
603595 defer tmp_dir.cleanup();
604596
605597 // First, create a couple of entries to iterate over.
606 const file = try tmp_dir.dir.createFile("some_file", .{});
598 const file = try tmp_dir.dir.createFile(io, "some_file", .{});
607599 file.close(io);
608600
609601 try tmp_dir.dir.makeDir("some_dir");
......@@ -638,7 +630,7 @@ test "Dir.Iterator reset" {
638630 defer tmp_dir.cleanup();
639631
640632 // First, create a couple of entries to iterate over.
641 const file = try tmp_dir.dir.createFile("some_file", .{});
633 const file = try tmp_dir.dir.createFile(io, "some_file", .{});
642634 file.close(io);
643635
644636 try tmp_dir.dir.makeDir("some_dir");
......@@ -769,7 +761,7 @@ test "readFileAlloc" {
769761 var tmp_dir = tmpDir(.{});
770762 defer tmp_dir.cleanup();
771763
772 var file = try tmp_dir.dir.createFile("test_file", .{ .read = true });
764 var file = try tmp_dir.dir.createFile(io, "test_file", .{ .read = true });
773765 defer file.close(io);
774766
775767 const buf1 = try tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(1024));
......@@ -843,7 +835,7 @@ test "directory operations on files" {
843835
844836 const test_file_name = try ctx.transformPath("test_file");
845837
846 var file = try ctx.dir.createFile(test_file_name, .{ .read = true });
838 var file = try ctx.dir.createFile(io, test_file_name, .{ .read = true });
847839 file.close(io);
848840
849841 try testing.expectError(error.PathAlreadyExists, ctx.dir.makeDir(test_file_name));
......@@ -876,7 +868,7 @@ test "file operations on directories" {
876868
877869 try ctx.dir.makeDir(test_dir_name);
878870
879 try testing.expectError(error.IsDir, ctx.dir.createFile(test_dir_name, .{}));
871 try testing.expectError(error.IsDir, ctx.dir.createFile(io, test_dir_name, .{}));
880872 try testing.expectError(error.IsDir, ctx.dir.deleteFile(test_dir_name));
881873 switch (native_os) {
882874 .dragonfly, .netbsd => {
......@@ -969,7 +961,7 @@ test "Dir.rename files" {
969961 // Renaming files
970962 const test_file_name = try ctx.transformPath("test_file");
971963 const renamed_test_file_name = try ctx.transformPath("test_file_renamed");
972 var file = try ctx.dir.createFile(test_file_name, .{ .read = true });
964 var file = try ctx.dir.createFile(io, test_file_name, .{ .read = true });
973965 file.close(io);
974966 try ctx.dir.rename(test_file_name, renamed_test_file_name);
975967
......@@ -983,7 +975,7 @@ test "Dir.rename files" {
983975
984976 // Rename to existing file succeeds
985977 const existing_file_path = try ctx.transformPath("existing_file");
986 var existing_file = try ctx.dir.createFile(existing_file_path, .{ .read = true });
978 var existing_file = try ctx.dir.createFile(io, existing_file_path, .{ .read = true });
987979 existing_file.close(io);
988980 try ctx.dir.rename(renamed_test_file_name, existing_file_path);
989981
......@@ -1017,7 +1009,7 @@ test "Dir.rename directories" {
10171009 var dir = try ctx.dir.openDir(test_dir_renamed_path, .{});
10181010
10191011 // Put a file in the directory
1020 var file = try dir.createFile("test_file", .{ .read = true });
1012 var file = try dir.createFile(io, "test_file", .{ .read = true });
10211013 file.close(io);
10221014 dir.close(io);
10231015
......@@ -1070,7 +1062,7 @@ test "Dir.rename directory onto non-empty dir" {
10701062 try ctx.dir.makeDir(test_dir_path);
10711063
10721064 var target_dir = try ctx.dir.makeOpenPath(target_dir_path, .{});
1073 var file = try target_dir.createFile("test_file", .{ .read = true });
1065 var file = try target_dir.createFile(io, "test_file", .{ .read = true });
10741066 file.close(io);
10751067 target_dir.close(io);
10761068
......@@ -1094,7 +1086,7 @@ test "Dir.rename file <-> dir" {
10941086 const test_file_path = try ctx.transformPath("test_file");
10951087 const test_dir_path = try ctx.transformPath("test_dir");
10961088
1097 var file = try ctx.dir.createFile(test_file_path, .{ .read = true });
1089 var file = try ctx.dir.createFile(io, test_file_path, .{ .read = true });
10981090 file.close(io);
10991091 try ctx.dir.makeDir(test_dir_path);
11001092 try testing.expectError(error.IsDir, ctx.dir.rename(test_file_path, test_dir_path));
......@@ -1115,7 +1107,7 @@ test "rename" {
11151107 // Renaming files
11161108 const test_file_name = "test_file";
11171109 const renamed_test_file_name = "test_file_renamed";
1118 var file = try tmp_dir1.dir.createFile(test_file_name, .{ .read = true });
1110 var file = try tmp_dir1.dir.createFile(io, test_file_name, .{ .read = true });
11191111 file.close(io);
11201112 try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name);
11211113
......@@ -1149,7 +1141,7 @@ test "renameAbsolute" {
11491141 // Renaming files
11501142 const test_file_name = "test_file";
11511143 const renamed_test_file_name = "test_file_renamed";
1152 var file = try tmp_dir.dir.createFile(test_file_name, .{ .read = true });
1144 var file = try tmp_dir.dir.createFile(io, test_file_name, .{ .read = true });
11531145 file.close(io);
11541146 try fs.renameAbsolute(
11551147 try fs.path.join(allocator, &.{ base_path, test_file_name }),
......@@ -1454,7 +1446,7 @@ test "writev, readv" {
14541446 var write_vecs: [2][]const u8 = .{ line1, line2 };
14551447 var read_vecs: [2][]u8 = .{ &buf2, &buf1 };
14561448
1457 var src_file = try tmp.dir.createFile("test.txt", .{ .read = true });
1449 var src_file = try tmp.dir.createFile(io, "test.txt", .{ .read = true });
14581450 defer src_file.close(io);
14591451
14601452 var writer = src_file.writerStreaming(&.{});
......@@ -1484,7 +1476,7 @@ test "pwritev, preadv" {
14841476 var buf2: [line2.len]u8 = undefined;
14851477 var read_vecs: [2][]u8 = .{ &buf2, &buf1 };
14861478
1487 var src_file = try tmp.dir.createFile("test.txt", .{ .read = true });
1479 var src_file = try tmp.dir.createFile(io, "test.txt", .{ .read = true });
14881480 defer src_file.close(io);
14891481
14901482 var writer = src_file.writer(&.{});
......@@ -1584,14 +1576,14 @@ test "sendfile" {
15841576 const line2 = "second line\n";
15851577 var vecs = [_][]const u8{ line1, line2 };
15861578
1587 var src_file = try dir.createFile("sendfile1.txt", .{ .read = true });
1579 var src_file = try dir.createFile(io, "sendfile1.txt", .{ .read = true });
15881580 defer src_file.close(io);
15891581 {
15901582 var fw = src_file.writer(&.{});
15911583 try fw.interface.writeVecAll(&vecs);
15921584 }
15931585
1594 var dest_file = try dir.createFile("sendfile2.txt", .{ .read = true });
1586 var dest_file = try dir.createFile(io, "sendfile2.txt", .{ .read = true });
15951587 defer dest_file.close(io);
15961588
15971589 const header1 = "header1\n";
......@@ -1627,12 +1619,12 @@ test "sendfile with buffered data" {
16271619 var dir = try tmp.dir.openDir("os_test_tmp", .{});
16281620 defer dir.close(io);
16291621
1630 var src_file = try dir.createFile("sendfile1.txt", .{ .read = true });
1622 var src_file = try dir.createFile(io, "sendfile1.txt", .{ .read = true });
16311623 defer src_file.close(io);
16321624
16331625 try src_file.writeAll("AAAABBBB");
16341626
1635 var dest_file = try dir.createFile("sendfile2.txt", .{ .read = true });
1627 var dest_file = try dir.createFile(io, "sendfile2.txt", .{ .read = true });
16361628 defer dest_file.close(io);
16371629
16381630 var src_buffer: [32]u8 = undefined;
......@@ -1718,10 +1710,10 @@ test "open file with exclusive nonblocking lock twice" {
17181710 const io = ctx.io;
17191711 const filename = try ctx.transformPath("file_nonblocking_lock_test.txt");
17201712
1721 const file1 = try ctx.dir.createFile(filename, .{ .lock = .exclusive, .lock_nonblocking = true });
1713 const file1 = try ctx.dir.createFile(io, filename, .{ .lock = .exclusive, .lock_nonblocking = true });
17221714 defer file1.close(io);
17231715
1724 const file2 = ctx.dir.createFile(filename, .{ .lock = .exclusive, .lock_nonblocking = true });
1716 const file2 = ctx.dir.createFile(io, filename, .{ .lock = .exclusive, .lock_nonblocking = true });
17251717 try testing.expectError(error.WouldBlock, file2);
17261718 }
17271719 }.impl);
......@@ -1735,10 +1727,10 @@ test "open file with shared and exclusive nonblocking lock" {
17351727 const io = ctx.io;
17361728 const filename = try ctx.transformPath("file_nonblocking_lock_test.txt");
17371729
1738 const file1 = try ctx.dir.createFile(filename, .{ .lock = .shared, .lock_nonblocking = true });
1730 const file1 = try ctx.dir.createFile(io, filename, .{ .lock = .shared, .lock_nonblocking = true });
17391731 defer file1.close(io);
17401732
1741 const file2 = ctx.dir.createFile(filename, .{ .lock = .exclusive, .lock_nonblocking = true });
1733 const file2 = ctx.dir.createFile(io, filename, .{ .lock = .exclusive, .lock_nonblocking = true });
17421734 try testing.expectError(error.WouldBlock, file2);
17431735 }
17441736 }.impl);
......@@ -1752,10 +1744,10 @@ test "open file with exclusive and shared nonblocking lock" {
17521744 const io = ctx.io;
17531745 const filename = try ctx.transformPath("file_nonblocking_lock_test.txt");
17541746
1755 const file1 = try ctx.dir.createFile(filename, .{ .lock = .exclusive, .lock_nonblocking = true });
1747 const file1 = try ctx.dir.createFile(io, filename, .{ .lock = .exclusive, .lock_nonblocking = true });
17561748 defer file1.close(io);
17571749
1758 const file2 = ctx.dir.createFile(filename, .{ .lock = .shared, .lock_nonblocking = true });
1750 const file2 = ctx.dir.createFile(io, filename, .{ .lock = .shared, .lock_nonblocking = true });
17591751 try testing.expectError(error.WouldBlock, file2);
17601752 }
17611753 }.impl);
......@@ -1769,13 +1761,13 @@ test "open file with exclusive lock twice, make sure second lock waits" {
17691761 const io = ctx.io;
17701762 const filename = try ctx.transformPath("file_lock_test.txt");
17711763
1772 const file = try ctx.dir.createFile(filename, .{ .lock = .exclusive });
1764 const file = try ctx.dir.createFile(io, filename, .{ .lock = .exclusive });
17731765 errdefer file.close(io);
17741766
17751767 const S = struct {
17761768 fn checkFn(dir: *Io.Dir, path: []const u8, started: *std.Thread.ResetEvent, locked: *std.Thread.ResetEvent) !void {
17771769 started.set();
1778 const file1 = try dir.createFile(path, .{ .lock = .exclusive });
1770 const file1 = try dir.createFile(io, path, .{ .lock = .exclusive });
17791771
17801772 locked.set();
17811773 file1.close(io);
......@@ -1847,13 +1839,13 @@ test "read from locked file" {
18471839 const filename = try ctx.transformPath("read_lock_file_test.txt");
18481840
18491841 {
1850 const f = try ctx.dir.createFile(filename, .{ .read = true });
1842 const f = try ctx.dir.createFile(io, filename, .{ .read = true });
18511843 defer f.close(io);
18521844 var buffer: [1]u8 = undefined;
18531845 _ = try f.read(&buffer);
18541846 }
18551847 {
1856 const f = try ctx.dir.createFile(filename, .{
1848 const f = try ctx.dir.createFile(io, filename, .{
18571849 .read = true,
18581850 .lock = .exclusive,
18591851 });
......@@ -2037,7 +2029,7 @@ test "'.' and '..' in Io.Dir functions" {
20372029 var created_subdir = try ctx.dir.openDir(subdir_path, .{});
20382030 created_subdir.close(io);
20392031
2040 const created_file = try ctx.dir.createFile(file_path, .{});
2032 const created_file = try ctx.dir.createFile(io, file_path, .{});
20412033 created_file.close(io);
20422034 try ctx.dir.access(file_path, .{});
20432035
......@@ -2103,7 +2095,7 @@ test "chmod" {
21032095 var tmp = tmpDir(.{});
21042096 defer tmp.cleanup();
21052097
2106 const file = try tmp.dir.createFile("test_file", .{ .mode = 0o600 });
2098 const file = try tmp.dir.createFile(io, "test_file", .{ .mode = 0o600 });
21072099 defer file.close(io);
21082100 try testing.expectEqual(@as(File.Mode, 0o600), (try file.stat()).mode & 0o7777);
21092101
......@@ -2127,7 +2119,7 @@ test "chown" {
21272119 var tmp = tmpDir(.{});
21282120 defer tmp.cleanup();
21292121
2130 const file = try tmp.dir.createFile("test_file", .{});
2122 const file = try tmp.dir.createFile(io, "test_file", .{});
21312123 defer file.close(io);
21322124 try file.chown(null, null);
21332125
......@@ -2228,7 +2220,7 @@ test "read file non vectored" {
22282220
22292221 const contents = "hello, world!\n";
22302222
2231 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });
2223 const file = try tmp_dir.dir.createFile(io, "input.txt", .{ .read = true });
22322224 defer file.close(io);
22332225 {
22342226 var file_writer: File.Writer = .init(file, &.{});
......@@ -2260,7 +2252,7 @@ test "seek keeping partial buffer" {
22602252
22612253 const contents = "0123456789";
22622254
2263 const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });
2255 const file = try tmp_dir.dir.createFile(io, "input.txt", .{ .read = true });
22642256 defer file.close(io);
22652257 {
22662258 var file_writer: File.Writer = .init(file, &.{});
......@@ -2321,7 +2313,7 @@ test "seekTo flushes buffered data" {
23212313
23222314 const contents = "data";
23232315
2324 const file = try tmp.dir.createFile("seek.bin", .{ .read = true });
2316 const file = try tmp.dir.createFile(io, "seek.bin", .{ .read = true });
23252317 defer file.close(io);
23262318 {
23272319 var buf: [16]u8 = undefined;
......@@ -2350,7 +2342,7 @@ test "File.Writer sendfile with buffered contents" {
23502342 try tmp_dir.dir.writeFile(.{ .sub_path = "a", .data = "bcd" });
23512343 const in = try tmp_dir.dir.openFile(io, "a", .{});
23522344 defer in.close(io);
2353 const out = try tmp_dir.dir.createFile("b", .{});
2345 const out = try tmp_dir.dir.createFile(io, "b", .{});
23542346 defer out.close(io);
23552347
23562348 var in_buf: [2]u8 = undefined;
......@@ -2397,7 +2389,7 @@ test "readlinkat" {
23972389 // create a symbolic link
23982390 if (native_os == .windows) {
23992391 std.os.windows.CreateSymbolicLink(
2400 tmp.dir.fd,
2392 tmp.dir.handle,
24012393 &[_]u16{ 'l', 'i', 'n', 'k' },
24022394 &[_:0]u16{ 'f', 'i', 'l', 'e', '.', 't', 'x', 't' },
24032395 false,
......@@ -2407,7 +2399,7 @@ test "readlinkat" {
24072399 else => return err,
24082400 };
24092401 } else {
2410 try posix.symlinkat("file.txt", tmp.dir.fd, "link");
2402 try posix.symlinkat("file.txt", tmp.dir.handle, "link");
24112403 }
24122404
24132405 // read the link
lib/std/os/linux/IoUring.zig+12-12
......@@ -1991,7 +1991,7 @@ test "writev/fsync/readv" {
19911991 defer tmp.cleanup();
19921992
19931993 const path = "test_io_uring_writev_fsync_readv";
1994 const file = try tmp.dir.createFile(path, .{ .read = true, .truncate = true });
1994 const file = try tmp.dir.createFile(io, path, .{ .read = true, .truncate = true });
19951995 defer file.close(io);
19961996 const fd = file.handle;
19971997
......@@ -2062,7 +2062,7 @@ test "write/read" {
20622062 var tmp = std.testing.tmpDir(.{});
20632063 defer tmp.cleanup();
20642064 const path = "test_io_uring_write_read";
2065 const file = try tmp.dir.createFile(path, .{ .read = true, .truncate = true });
2065 const file = try tmp.dir.createFile(io, path, .{ .read = true, .truncate = true });
20662066 defer file.close(io);
20672067 const fd = file.handle;
20682068
......@@ -2110,12 +2110,12 @@ test "splice/read" {
21102110
21112111 var tmp = std.testing.tmpDir(.{});
21122112 const path_src = "test_io_uring_splice_src";
2113 const file_src = try tmp.dir.createFile(path_src, .{ .read = true, .truncate = true });
2113 const file_src = try tmp.dir.createFile(io, path_src, .{ .read = true, .truncate = true });
21142114 defer file_src.close(io);
21152115 const fd_src = file_src.handle;
21162116
21172117 const path_dst = "test_io_uring_splice_dst";
2118 const file_dst = try tmp.dir.createFile(path_dst, .{ .read = true, .truncate = true });
2118 const file_dst = try tmp.dir.createFile(io, path_dst, .{ .read = true, .truncate = true });
21192119 defer file_dst.close(io);
21202120 const fd_dst = file_dst.handle;
21212121
......@@ -2185,7 +2185,7 @@ test "write_fixed/read_fixed" {
21852185 defer tmp.cleanup();
21862186
21872187 const path = "test_io_uring_write_read_fixed";
2188 const file = try tmp.dir.createFile(path, .{ .read = true, .truncate = true });
2188 const file = try tmp.dir.createFile(io, path, .{ .read = true, .truncate = true });
21892189 defer file.close(io);
21902190 const fd = file.handle;
21912191
......@@ -2306,7 +2306,7 @@ test "close" {
23062306 defer tmp.cleanup();
23072307
23082308 const path = "test_io_uring_close";
2309 const file = try tmp.dir.createFile(path, .{});
2309 const file = try tmp.dir.createFile(io, path, .{});
23102310 errdefer file.close(io);
23112311
23122312 const sqe_close = try ring.close(0x44444444, file.handle);
......@@ -2652,7 +2652,7 @@ test "fallocate" {
26522652 defer tmp.cleanup();
26532653
26542654 const path = "test_io_uring_fallocate";
2655 const file = try tmp.dir.createFile(path, .{ .truncate = true, .mode = 0o666 });
2655 const file = try tmp.dir.createFile(io, path, .{ .truncate = true, .mode = 0o666 });
26562656 defer file.close(io);
26572657
26582658 try testing.expectEqual(@as(u64, 0), (try file.stat()).size);
......@@ -2699,7 +2699,7 @@ test "statx" {
26992699 var tmp = std.testing.tmpDir(.{});
27002700 defer tmp.cleanup();
27012701 const path = "test_io_uring_statx";
2702 const file = try tmp.dir.createFile(path, .{ .truncate = true, .mode = 0o666 });
2702 const file = try tmp.dir.createFile(io, path, .{ .truncate = true, .mode = 0o666 });
27032703 defer file.close(io);
27042704
27052705 try testing.expectEqual(@as(u64, 0), (try file.stat()).size);
......@@ -2969,7 +2969,7 @@ test "renameat" {
29692969
29702970 // Write old file with data
29712971
2972 const old_file = try tmp.dir.createFile(old_path, .{ .truncate = true, .mode = 0o666 });
2972 const old_file = try tmp.dir.createFile(io, old_path, .{ .truncate = true, .mode = 0o666 });
29732973 defer old_file.close(io);
29742974 try old_file.writeAll("hello");
29752975
......@@ -3028,7 +3028,7 @@ test "unlinkat" {
30283028
30293029 // Write old file with data
30303030
3031 const file = try tmp.dir.createFile(path, .{ .truncate = true, .mode = 0o666 });
3031 const file = try tmp.dir.createFile(io, path, .{ .truncate = true, .mode = 0o666 });
30323032 defer file.close(io);
30333033
30343034 // Submit unlinkat
......@@ -3125,7 +3125,7 @@ test "symlinkat" {
31253125 const path = "test_io_uring_symlinkat";
31263126 const link_path = "test_io_uring_symlinkat_link";
31273127
3128 const file = try tmp.dir.createFile(path, .{ .truncate = true, .mode = 0o666 });
3128 const file = try tmp.dir.createFile(io, path, .{ .truncate = true, .mode = 0o666 });
31293129 defer file.close(io);
31303130
31313131 // Submit symlinkat
......@@ -3177,7 +3177,7 @@ test "linkat" {
31773177
31783178 // Write file with data
31793179
3180 const first_file = try tmp.dir.createFile(first_path, .{ .truncate = true, .mode = 0o666 });
3180 const first_file = try tmp.dir.createFile(io, first_path, .{ .truncate = true, .mode = 0o666 });
31813181 defer first_file.close(io);
31823182 try first_file.writeAll("hello");
31833183
lib/std/os/linux/test.zig+3-3
......@@ -18,7 +18,7 @@ test "fallocate" {
1818 defer tmp.cleanup();
1919
2020 const path = "test_fallocate";
21 const file = try tmp.dir.createFile(path, .{ .truncate = true, .mode = 0o666 });
21 const file = try tmp.dir.createFile(io, path, .{ .truncate = true, .mode = 0o666 });
2222 defer file.close(io);
2323
2424 try expect((try file.stat()).size == 0);
......@@ -85,7 +85,7 @@ test "statx" {
8585 defer tmp.cleanup();
8686
8787 const tmp_file_name = "just_a_temporary_file.txt";
88 var file = try tmp.dir.createFile(tmp_file_name, .{});
88 var file = try tmp.dir.createFile(io, tmp_file_name, .{});
8989 defer file.close(io);
9090
9191 var buf: linux.Statx = undefined;
......@@ -121,7 +121,7 @@ test "fadvise" {
121121 defer tmp.cleanup();
122122
123123 const tmp_file_name = "temp_posix_fadvise.txt";
124 var file = try tmp.dir.createFile(tmp_file_name, .{});
124 var file = try tmp.dir.createFile(io, tmp_file_name, .{});
125125 defer file.close(io);
126126
127127 var buf: [2048]u8 = undefined;
lib/std/os/windows.zig+2-2
......@@ -4639,8 +4639,8 @@ pub fn wToPrefixedFileW(dir: ?HANDLE, path: [:0]const u16) Wtf16ToPrefixedFileWE
46394639 break :path_to_get path;
46404640 }
46414641 // We can also skip GetFinalPathNameByHandle if the handle matches
4642 // the handle returned by fs.cwd()
4643 if (dir.? == std.fs.cwd().fd) {
4642 // the handle returned by Io.Dir.cwd()
4643 if (dir.? == Io.Dir.cwd().fd) {
46444644 break :path_to_get path;
46454645 }
46464646 // At this point, we know we have a relative path that had too many
lib/std/posix.zig+7-7
......@@ -15,15 +15,16 @@
1515//! deal with the exception.
1616
1717const builtin = @import("builtin");
18const root = @import("root");
18const native_os = builtin.os.tag;
19
1920const std = @import("std.zig");
21const Io = std.Io;
2022const mem = std.mem;
2123const fs = std.fs;
22const max_path_bytes = fs.max_path_bytes;
24const max_path_bytes = std.fs.max_path_bytes;
2325const maxInt = std.math.maxInt;
2426const cast = std.math.cast;
2527const assert = std.debug.assert;
26const native_os = builtin.os.tag;
2728const page_size_min = std.heap.page_size_min;
2829
2930test {
......@@ -797,7 +798,6 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
797798 .INTR => continue,
798799 .INVAL => unreachable,
799800 .FAULT => unreachable,
800 .SRCH => return error.ProcessNotFound,
801801 .AGAIN => return error.WouldBlock,
802802 .CANCELED => return error.Canceled,
803803 .BADF => return error.NotOpenForReading, // Can be a race condition.
......@@ -917,7 +917,6 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
917917 .INTR => continue,
918918 .INVAL => return error.InvalidArgument,
919919 .FAULT => unreachable,
920 .SRCH => return error.ProcessNotFound,
921920 .AGAIN => return error.WouldBlock,
922921 .BADF => return error.NotOpenForWriting, // can be a race condition.
923922 .DESTADDRREQ => unreachable, // `connect` was never called.
......@@ -985,7 +984,8 @@ pub fn openZ(file_path: [*:0]const u8, flags: O, perm: mode_t) OpenError!fd_t {
985984 .NFILE => return error.SystemFdQuotaExceeded,
986985 .NODEV => return error.NoDevice,
987986 .NOENT => return error.FileNotFound,
988 .SRCH => return error.ProcessNotFound,
987 // Can happen on Linux when opening procfs files.
988 .SRCH => return error.FileNotFound,
989989 .NOMEM => return error.SystemResources,
990990 .NOSPC => return error.NoSpaceLeft,
991991 .NOTDIR => return error.NotDir,
......@@ -1560,7 +1560,7 @@ pub fn mkdirZ(dir_path: [*:0]const u8, mode: mode_t) MakeDirError!void {
15601560pub fn mkdirW(dir_path_w: []const u16, mode: mode_t) MakeDirError!void {
15611561 _ = mode;
15621562 const sub_dir_handle = windows.OpenFile(dir_path_w, .{
1563 .dir = fs.cwd().fd,
1563 .dir = Io.Dir.cwd().handle,
15641564 .access_mask = .{
15651565 .STANDARD = .{ .SYNCHRONIZE = true },
15661566 .GENERIC = .{ .READ = true },
lib/std/posix/test.zig+26-26
......@@ -148,7 +148,7 @@ test "linkat with different directories" {
148148 try tmp.dir.writeFile(.{ .sub_path = target_name, .data = "example" });
149149
150150 // Test 1: link from file in subdir back up to target in parent directory
151 try posix.linkat(tmp.dir.fd, target_name, subdir.fd, link_name, 0);
151 try posix.linkat(tmp.dir.handle, target_name, subdir.handle, link_name, 0);
152152
153153 const efd = try tmp.dir.openFile(io, target_name, .{});
154154 defer efd.close(io);
......@@ -164,7 +164,7 @@ test "linkat with different directories" {
164164 }
165165
166166 // Test 2: remove link
167 try posix.unlinkat(subdir.fd, link_name, 0);
167 try posix.unlinkat(subdir.handle, link_name, 0);
168168 _, const elink = try getLinkInfo(efd.handle);
169169 try testing.expectEqual(@as(posix.nlink_t, 1), elink);
170170}
......@@ -373,7 +373,7 @@ test "mmap" {
373373
374374 // Create a file used for testing mmap() calls with a file descriptor
375375 {
376 const file = try tmp.dir.createFile(test_out_file, .{});
376 const file = try tmp.dir.createFile(io, test_out_file, .{});
377377 defer file.close(io);
378378
379379 var stream = file.writer(&.{});
......@@ -444,7 +444,7 @@ test "fcntl" {
444444
445445 const test_out_file = "os_tmp_test";
446446
447 const file = try tmp.dir.createFile(test_out_file, .{});
447 const file = try tmp.dir.createFile(io, test_out_file, .{});
448448 defer file.close(io);
449449
450450 // Note: The test assumes createFile opens the file with CLOEXEC
......@@ -495,7 +495,7 @@ test "fsync" {
495495 defer tmp.cleanup();
496496
497497 const test_out_file = "os_tmp_test";
498 const file = try tmp.dir.createFile(test_out_file, .{});
498 const file = try tmp.dir.createFile(io, test_out_file, .{});
499499 defer file.close(io);
500500
501501 try posix.fsync(file.handle);
......@@ -617,7 +617,7 @@ test "dup & dup2" {
617617 defer tmp.cleanup();
618618
619619 {
620 var file = try tmp.dir.createFile("os_dup_test", .{});
620 var file = try tmp.dir.createFile(io, "os_dup_test", .{});
621621 defer file.close(io);
622622
623623 var duped = Io.File{ .handle = try posix.dup(file.handle) };
......@@ -659,7 +659,7 @@ test "writev longer than IOV_MAX" {
659659 var tmp = tmpDir(.{});
660660 defer tmp.cleanup();
661661
662 var file = try tmp.dir.createFile("pwritev", .{});
662 var file = try tmp.dir.createFile(io, "pwritev", .{});
663663 defer file.close(io);
664664
665665 const iovecs = [_]posix.iovec_const{.{ .base = "a", .len = 1 }} ** (posix.IOV_MAX + 1);
......@@ -684,7 +684,7 @@ test "POSIX file locking with fcntl" {
684684 defer tmp.cleanup();
685685
686686 // Create a temporary lock file
687 var file = try tmp.dir.createFile("lock", .{ .read = true });
687 var file = try tmp.dir.createFile(io, "lock", .{ .read = true });
688688 defer file.close(io);
689689 try file.setEndPos(2);
690690 const fd = file.handle;
......@@ -881,7 +881,7 @@ test "isatty" {
881881 var tmp = tmpDir(.{});
882882 defer tmp.cleanup();
883883
884 var file = try tmp.dir.createFile("foo", .{});
884 var file = try tmp.dir.createFile(io, "foo", .{});
885885 defer file.close(io);
886886
887887 try expectEqual(posix.isatty(file.handle), false);
......@@ -893,7 +893,7 @@ test "pread with empty buffer" {
893893 var tmp = tmpDir(.{});
894894 defer tmp.cleanup();
895895
896 var file = try tmp.dir.createFile("pread_empty", .{ .read = true });
896 var file = try tmp.dir.createFile(io, "pread_empty", .{ .read = true });
897897 defer file.close(io);
898898
899899 const bytes = try a.alloc(u8, 0);
......@@ -909,7 +909,7 @@ test "write with empty buffer" {
909909 var tmp = tmpDir(.{});
910910 defer tmp.cleanup();
911911
912 var file = try tmp.dir.createFile("write_empty", .{});
912 var file = try tmp.dir.createFile(io, "write_empty", .{});
913913 defer file.close(io);
914914
915915 const bytes = try a.alloc(u8, 0);
......@@ -925,7 +925,7 @@ test "pwrite with empty buffer" {
925925 var tmp = tmpDir(.{});
926926 defer tmp.cleanup();
927927
928 var file = try tmp.dir.createFile("pwrite_empty", .{});
928 var file = try tmp.dir.createFile(io, "pwrite_empty", .{});
929929 defer file.close(io);
930930
931931 const bytes = try a.alloc(u8, 0);
......@@ -965,35 +965,35 @@ test "fchmodat smoke test" {
965965 var tmp = tmpDir(.{});
966966 defer tmp.cleanup();
967967
968 try expectError(error.FileNotFound, posix.fchmodat(tmp.dir.fd, "regfile", 0o666, 0));
968 try expectError(error.FileNotFound, posix.fchmodat(tmp.dir.handle, "regfile", 0o666, 0));
969969 const fd = try posix.openat(
970 tmp.dir.fd,
970 tmp.dir.handle,
971971 "regfile",
972972 .{ .ACCMODE = .WRONLY, .CREAT = true, .EXCL = true, .TRUNC = true },
973973 0o644,
974974 );
975975 posix.close(fd);
976976
977 try posix.symlinkat("regfile", tmp.dir.fd, "symlink");
978 const sym_mode = try getFileMode(tmp.dir.fd, "symlink");
977 try posix.symlinkat("regfile", tmp.dir.handle, "symlink");
978 const sym_mode = try getFileMode(tmp.dir.handle, "symlink");
979979
980 try posix.fchmodat(tmp.dir.fd, "regfile", 0o640, 0);
981 try expectMode(tmp.dir.fd, "regfile", 0o640);
982 try posix.fchmodat(tmp.dir.fd, "regfile", 0o600, posix.AT.SYMLINK_NOFOLLOW);
983 try expectMode(tmp.dir.fd, "regfile", 0o600);
980 try posix.fchmodat(tmp.dir.handle, "regfile", 0o640, 0);
981 try expectMode(tmp.dir.handle, "regfile", 0o640);
982 try posix.fchmodat(tmp.dir.handle, "regfile", 0o600, posix.AT.SYMLINK_NOFOLLOW);
983 try expectMode(tmp.dir.handle, "regfile", 0o600);
984984
985 try posix.fchmodat(tmp.dir.fd, "symlink", 0o640, 0);
986 try expectMode(tmp.dir.fd, "regfile", 0o640);
987 try expectMode(tmp.dir.fd, "symlink", sym_mode);
985 try posix.fchmodat(tmp.dir.handle, "symlink", 0o640, 0);
986 try expectMode(tmp.dir.handle, "regfile", 0o640);
987 try expectMode(tmp.dir.handle, "symlink", sym_mode);
988988
989989 var test_link = true;
990 posix.fchmodat(tmp.dir.fd, "symlink", 0o600, posix.AT.SYMLINK_NOFOLLOW) catch |err| switch (err) {
990 posix.fchmodat(tmp.dir.handle, "symlink", 0o600, posix.AT.SYMLINK_NOFOLLOW) catch |err| switch (err) {
991991 error.OperationNotSupported => test_link = false,
992992 else => |e| return e,
993993 };
994994 if (test_link)
995 try expectMode(tmp.dir.fd, "symlink", 0o600);
996 try expectMode(tmp.dir.fd, "regfile", 0o640);
995 try expectMode(tmp.dir.handle, "symlink", 0o600);
996 try expectMode(tmp.dir.handle, "regfile", 0o640);
997997}
998998
999999const CommonOpenFlags = packed struct {
lib/std/process/Child.zig+1-1
......@@ -677,7 +677,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
677677 setUpChildIo(self.stderr_behavior, stderr_pipe[1], posix.STDERR_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err);
678678
679679 if (self.cwd_dir) |cwd| {
680 posix.fchdir(cwd.fd) catch |err| forkChildErrReport(err_pipe[1], err);
680 posix.fchdir(cwd.handle) catch |err| forkChildErrReport(err_pipe[1], err);
681681 } else if (self.cwd) |cwd| {
682682 posix.chdir(cwd) catch |err| forkChildErrReport(err_pipe[1], err);
683683 }
lib/std/std.zig+1-1
......@@ -114,7 +114,7 @@ pub const options: Options = if (@hasDecl(root, "std_options")) root.std_options
114114pub const Options = struct {
115115 enable_segfault_handler: bool = debug.default_enable_segfault_handler,
116116
117 /// Function used to implement `std.fs.cwd` for WASI.
117 /// Function used to implement `std.Io.Dir.cwd` for WASI.
118118 wasiCwd: fn () os.wasi.fd_t = os.defaultWasiCwd,
119119
120120 /// The current log level.
lib/std/tar.zig+7-7
......@@ -610,7 +610,7 @@ pub fn pipeToFileSystem(io: Io, dir: Io.Dir, reader: *Io.Reader, options: PipeOp
610610 }
611611 },
612612 .file => {
613 if (createDirAndFile(dir, file_name, fileMode(file.mode, options))) |fs_file| {
613 if (createDirAndFile(io, dir, file_name, fileMode(file.mode, options))) |fs_file| {
614614 defer fs_file.close(io);
615615 var file_writer = fs_file.writer(&file_contents_buffer);
616616 try it.streamRemaining(file, &file_writer.interface);
......@@ -638,12 +638,12 @@ pub fn pipeToFileSystem(io: Io, dir: Io.Dir, reader: *Io.Reader, options: PipeOp
638638 }
639639}
640640
641fn createDirAndFile(dir: Io.Dir, file_name: []const u8, mode: Io.File.Mode) !Io.File {
642 const fs_file = dir.createFile(file_name, .{ .exclusive = true, .mode = mode }) catch |err| {
641fn createDirAndFile(io: Io, dir: Io.Dir, file_name: []const u8, mode: Io.File.Mode) !Io.File {
642 const fs_file = dir.createFile(io, file_name, .{ .exclusive = true, .mode = mode }) catch |err| {
643643 if (err == error.FileNotFound) {
644644 if (std.fs.path.dirname(file_name)) |dir_name| {
645645 try dir.makePath(dir_name);
646 return try dir.createFile(file_name, .{ .exclusive = true, .mode = mode });
646 return try dir.createFile(io, file_name, .{ .exclusive = true, .mode = mode });
647647 }
648648 }
649649 return err;
......@@ -880,9 +880,9 @@ test "create file and symlink" {
880880 var root = testing.tmpDir(.{});
881881 defer root.cleanup();
882882
883 var file = try createDirAndFile(root.dir, "file1", default_mode);
883 var file = try createDirAndFile(io, root.dir, "file1", default_mode);
884884 file.close(io);
885 file = try createDirAndFile(root.dir, "a/b/c/file2", default_mode);
885 file = try createDirAndFile(io, root.dir, "a/b/c/file2", default_mode);
886886 file.close(io);
887887
888888 createDirAndSymlink(root.dir, "a/b/c/file2", "symlink1") catch |err| {
......@@ -894,7 +894,7 @@ test "create file and symlink" {
894894
895895 // Danglink symlnik, file created later
896896 try createDirAndSymlink(root.dir, "../../../g/h/i/file4", "j/k/l/symlink3");
897 file = try createDirAndFile(root.dir, "g/h/i/file4", default_mode);
897 file = try createDirAndFile(io, root.dir, "g/h/i/file4", default_mode);
898898 file.close(io);
899899}
900900
lib/std/testing.zig+1-1
......@@ -628,7 +628,7 @@ pub fn tmpDir(opts: Io.Dir.OpenOptions) TmpDir {
628628 var sub_path: [TmpDir.sub_path_len]u8 = undefined;
629629 _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);
630630
631 const cwd = std.fs.cwd();
631 const cwd = Io.Dir.cwd();
632632 var cache_dir = cwd.makeOpenPath(".zig-cache", .{}) catch
633633 @panic("unable to make tmp dir for testing: unable to make and open .zig-cache dir");
634634 defer cache_dir.close(io);
lib/std/zig/LibCInstallation.zig+6-6
......@@ -57,7 +57,7 @@ pub fn parse(
5757 }
5858 }
5959
60 const contents = try std.fs.cwd().readFileAlloc(libc_file, allocator, .limited(std.math.maxInt(usize)));
60 const contents = try Io.Dir.cwd().readFileAlloc(libc_file, allocator, .limited(std.math.maxInt(usize)));
6161 defer allocator.free(contents);
6262
6363 var it = std.mem.tokenizeScalar(u8, contents, '\n');
......@@ -337,7 +337,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, args: FindNativeOptions) F
337337 // search in reverse order
338338 const search_path_untrimmed = search_paths.items[search_paths.items.len - path_i - 1];
339339 const search_path = std.mem.trimStart(u8, search_path_untrimmed, " ");
340 var search_dir = fs.cwd().openDir(search_path, .{}) catch |err| switch (err) {
340 var search_dir = Io.Dir.cwd().openDir(search_path, .{}) catch |err| switch (err) {
341341 error.FileNotFound,
342342 error.NotDir,
343343 error.NoDevice,
......@@ -392,7 +392,7 @@ fn findNativeIncludeDirWindows(
392392 result_buf.shrinkAndFree(0);
393393 try result_buf.print("{s}\\Include\\{s}\\ucrt", .{ install.path, install.version });
394394
395 var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {
395 var dir = Io.Dir.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {
396396 error.FileNotFound,
397397 error.NotDir,
398398 error.NoDevice,
......@@ -440,7 +440,7 @@ fn findNativeCrtDirWindows(
440440 result_buf.shrinkAndFree(0);
441441 try result_buf.print("{s}\\Lib\\{s}\\ucrt\\{s}", .{ install.path, install.version, arch_sub_dir });
442442
443 var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {
443 var dir = Io.Dir.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {
444444 error.FileNotFound,
445445 error.NotDir,
446446 error.NoDevice,
......@@ -508,7 +508,7 @@ fn findNativeKernel32LibDir(
508508 result_buf.shrinkAndFree(0);
509509 try result_buf.print("{s}\\Lib\\{s}\\um\\{s}", .{ install.path, install.version, arch_sub_dir });
510510
511 var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {
511 var dir = Io.Dir.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) {
512512 error.FileNotFound,
513513 error.NotDir,
514514 error.NoDevice,
......@@ -544,7 +544,7 @@ fn findNativeMsvcIncludeDir(
544544 const dir_path = try fs.path.join(allocator, &[_][]const u8{ up2, "include" });
545545 errdefer allocator.free(dir_path);
546546
547 var dir = fs.cwd().openDir(dir_path, .{}) catch |err| switch (err) {
547 var dir = Io.Dir.cwd().openDir(dir_path, .{}) catch |err| switch (err) {
548548 error.FileNotFound,
549549 error.NotDir,
550550 error.NoDevice,
lib/std/zig/WindowsSdk.zig+1-1
......@@ -828,7 +828,7 @@ const MsvcLibDir = struct {
828828
829829 try lib_dir_buf.appendSlice("VC\\Auxiliary\\Build\\Microsoft.VCToolsVersion.default.txt");
830830 var default_tools_version_buf: [512]u8 = undefined;
831 const default_tools_version_contents = std.fs.cwd().readFile(lib_dir_buf.items, &default_tools_version_buf) catch {
831 const default_tools_version_contents = Io.Dir.cwd().readFile(lib_dir_buf.items, &default_tools_version_buf) catch {
832832 return error.PathNotFound;
833833 };
834834 var tokenizer = std.mem.tokenizeAny(u8, default_tools_version_contents, " \r\n");
lib/std/zig/system.zig+4-2
......@@ -1,11 +1,12 @@
11const builtin = @import("builtin");
2const native_endian = builtin.cpu.arch.endian();
3
24const std = @import("../std.zig");
35const mem = std.mem;
46const elf = std.elf;
57const fs = std.fs;
68const assert = std.debug.assert;
79const Target = std.Target;
8const native_endian = builtin.cpu.arch.endian();
910const posix = std.posix;
1011const Io = std.Io;
1112
......@@ -69,7 +70,7 @@ pub fn getExternalExecutor(
6970 if (os_match and cpu_ok) native: {
7071 if (options.link_libc) {
7172 if (candidate.dynamic_linker.get()) |candidate_dl| {
72 fs.cwd().access(candidate_dl, .{}) catch {
73 Io.Dir.cwd().access(candidate_dl, .{}) catch {
7374 bad_result = .{ .bad_dl = candidate_dl };
7475 break :native;
7576 };
......@@ -710,6 +711,7 @@ fn abiAndDynamicLinkerFromFile(
710711 error.SystemResources,
711712 error.FileSystem,
712713 error.SymLinkLoop,
714 error.Canceled,
713715 error.Unexpected,
714716 => |e| return e,
715717 };
lib/std/zig/system/darwin/macos.zig+4-3
......@@ -1,9 +1,10 @@
1const std = @import("std");
21const builtin = @import("builtin");
2
3const std = @import("std");
4const Io = std.Io;
35const assert = std.debug.assert;
46const mem = std.mem;
57const testing = std.testing;
6
78const Target = std.Target;
89
910/// Detect macOS version.
......@@ -54,7 +55,7 @@ pub fn detect(target_os: *Target.Os) !void {
5455 // approx. 4 times historical file size
5556 var buf: [2048]u8 = undefined;
5657
57 if (std.fs.cwd().readFile(path, &buf)) |bytes| {
58 if (Io.Dir.cwd().readFile(path, &buf)) |bytes| {
5859 if (parseSystemVersion(bytes)) |ver| {
5960 // never return non-canonical `10.(16+)`
6061 if (!(ver.major == 10 and ver.minor >= 16)) {
lib/std/zip.zig+2-2
......@@ -564,9 +564,9 @@ pub const Iterator = struct {
564564 defer parent_dir.close(io);
565565
566566 const basename = std.fs.path.basename(filename);
567 break :blk try parent_dir.createFile(basename, .{ .exclusive = true });
567 break :blk try parent_dir.createFile(io, basename, .{ .exclusive = true });
568568 }
569 break :blk try dest.createFile(filename, .{ .exclusive = true });
569 break :blk try dest.createFile(io, filename, .{ .exclusive = true });
570570 };
571571 defer out_file.close(io);
572572 var out_file_buffer: [1024]u8 = undefined;
src/Compilation.zig+10-10
......@@ -450,7 +450,7 @@ pub const Path = struct {
450450 const dir = switch (p.root) {
451451 .none => {
452452 const cwd_sub_path = absToCwdRelative(p.sub_path, dirs.cwd);
453 return .{ fs.cwd(), cwd_sub_path };
453 return .{ Io.Dir.cwd(), cwd_sub_path };
454454 },
455455 .zig_lib => dirs.zig_lib.handle,
456456 .global_cache => dirs.global_cache.handle,
......@@ -723,7 +723,7 @@ pub const Directories = struct {
723723
724724 pub fn deinit(dirs: *Directories, io: Io) void {
725725 // The local and global caches could be the same.
726 const close_local = dirs.local_cache.handle.fd != dirs.global_cache.handle.fd;
726 const close_local = dirs.local_cache.handle.handle != dirs.global_cache.handle.handle;
727727
728728 dirs.global_cache.handle.close(io);
729729 if (close_local) dirs.local_cache.handle.close(io);
......@@ -814,7 +814,7 @@ pub const Directories = struct {
814814 return .{
815815 .path = if (std.mem.eql(u8, name, ".")) null else name,
816816 .handle = .{
817 .fd = preopens.find(name) orelse fatal("WASI preopen not found: '{s}'", .{name}),
817 .handle = preopens.find(name) orelse fatal("WASI preopen not found: '{s}'", .{name}),
818818 },
819819 };
820820 }
......@@ -824,8 +824,8 @@ pub const Directories = struct {
824824 };
825825 const nonempty_path = if (path.len == 0) "." else path;
826826 const handle_or_err = switch (thing) {
827 .@"zig lib" => fs.cwd().openDir(nonempty_path, .{}),
828 .@"global cache", .@"local cache" => fs.cwd().makeOpenPath(nonempty_path, .{}),
827 .@"zig lib" => Io.Dir.cwd().openDir(nonempty_path, .{}),
828 .@"global cache", .@"local cache" => Io.Dir.cwd().makeOpenPath(nonempty_path, .{}),
829829 };
830830 return .{
831831 .path = if (path.len == 0) null else path,
......@@ -1104,7 +1104,7 @@ pub const CObject = struct {
11041104 const source_line = source_line: {
11051105 if (diag.src_loc.offset == 0 or diag.src_loc.column == 0) break :source_line 0;
11061106
1107 const file = fs.cwd().openFile(io, file_name, .{}) catch break :source_line 0;
1107 const file = Io.Dir.cwd().openFile(io, file_name, .{}) catch break :source_line 0;
11081108 defer file.close(io);
11091109 var buffer: [1024]u8 = undefined;
11101110 var file_reader = file.reader(io, &buffer);
......@@ -1179,7 +1179,7 @@ pub const CObject = struct {
11791179 };
11801180
11811181 var buffer: [1024]u8 = undefined;
1182 const file = try fs.cwd().openFile(io, path, .{});
1182 const file = try Io.Dir.cwd().openFile(io, path, .{});
11831183 defer file.close(io);
11841184 var file_reader = file.reader(io, &buffer);
11851185 var bc = std.zig.llvm.BitcodeReader.init(gpa, .{ .reader = &file_reader.interface });
......@@ -2109,7 +2109,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
21092109 },
21102110 };
21112111 // These correspond to std.zig.Server.Message.PathPrefix.
2112 cache.addPrefix(.{ .path = null, .handle = fs.cwd() });
2112 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
21132113 cache.addPrefix(options.dirs.zig_lib);
21142114 cache.addPrefix(options.dirs.local_cache);
21152115 cache.addPrefix(options.dirs.global_cache);
......@@ -5220,7 +5220,7 @@ fn createDepFile(
52205220 binfile: Cache.Path,
52215221) anyerror!void {
52225222 var buf: [4096]u8 = undefined;
5223 var af = try std.fs.cwd().atomicFile(depfile, .{ .write_buffer = &buf });
5223 var af = try Io.Dir.cwd().atomicFile(depfile, .{ .write_buffer = &buf });
52245224 defer af.deinit();
52255225
52265226 comp.writeDepFile(binfile, &af.file_writer.interface) catch return af.file_writer.err.?;
......@@ -5284,7 +5284,7 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {
52845284 };
52855285 }
52865286
5287 var tar_file = out_dir.createFile("sources.tar", .{}) catch |err| {
5287 var tar_file = out_dir.createFile(io, "sources.tar", .{}) catch |err| {
52885288 return comp.lockAndSetMiscFailure(
52895289 .docs_copy,
52905290 "unable to create '{f}/sources.tar': {s}",
src/Package/Fetch.zig+6-6
......@@ -383,14 +383,14 @@ pub fn run(f: *Fetch) RunError!void {
383383 },
384384 .remote => |remote| remote,
385385 .path_or_url => |path_or_url| {
386 if (fs.cwd().openDir(path_or_url, .{ .iterate = true })) |dir| {
386 if (Io.Dir.cwd().openDir(path_or_url, .{ .iterate = true })) |dir| {
387387 var resource: Resource = .{ .dir = dir };
388388 return f.runResource(path_or_url, &resource, null);
389389 } else |dir_err| {
390390 var server_header_buffer: [init_resource_buffer_size]u8 = undefined;
391391
392392 const file_err = if (dir_err == error.NotDir) e: {
393 if (fs.cwd().openFile(io, path_or_url, .{})) |file| {
393 if (Io.Dir.cwd().openFile(io, path_or_url, .{})) |file| {
394394 var resource: Resource = .{ .file = file.reader(io, &server_header_buffer) };
395395 return f.runResource(path_or_url, &resource, null);
396396 } else |err| break :e err;
......@@ -1303,7 +1303,7 @@ fn unzip(
13031303 const random_integer = std.crypto.random.int(u64);
13041304 zip_path[prefix.len..][0..random_len].* = std.fmt.hex(random_integer);
13051305
1306 break cache_root.handle.createFile(&zip_path, .{
1306 break cache_root.handle.createFile(io, &zip_path, .{
13071307 .exclusive = true,
13081308 .read = true,
13091309 }) catch |err| switch (err) {
......@@ -1365,7 +1365,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
13651365 {
13661366 var pack_dir = try out_dir.makeOpenPath(".git", .{});
13671367 defer pack_dir.close(io);
1368 var pack_file = try pack_dir.createFile("pkg.pack", .{ .read = true });
1368 var pack_file = try pack_dir.createFile(io, "pkg.pack", .{ .read = true });
13691369 defer pack_file.close(io);
13701370 var pack_file_buffer: [4096]u8 = undefined;
13711371 var pack_file_reader = b: {
......@@ -1376,7 +1376,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
13761376 break :b pack_file_writer.moveToReader(io);
13771377 };
13781378
1379 var index_file = try pack_dir.createFile("pkg.idx", .{ .read = true });
1379 var index_file = try pack_dir.createFile(io, "pkg.idx", .{ .read = true });
13801380 defer index_file.close(io);
13811381 var index_file_buffer: [2000]u8 = undefined;
13821382 var index_file_writer = index_file.writer(&index_file_buffer);
......@@ -2235,7 +2235,7 @@ test "set executable bit based on file content" {
22352235fn saveEmbedFile(io: Io, comptime tarball_name: []const u8, dir: Io.Dir) !void {
22362236 //const tarball_name = "duplicate_paths_excluded.tar.gz";
22372237 const tarball_content = @embedFile("Fetch/testdata/" ++ tarball_name);
2238 var tmp_file = try dir.createFile(tarball_name, .{});
2238 var tmp_file = try dir.createFile(io, tarball_name, .{});
22392239 defer tmp_file.close(io);
22402240 try tmp_file.writeAll(tarball_content);
22412241}
src/Package/Fetch/git.zig+6-6
......@@ -264,7 +264,7 @@ pub const Repository = struct {
264264 try repository.odb.seekOid(entry.oid);
265265 const file_object = try repository.odb.readObject();
266266 if (file_object.type != .blob) return error.InvalidFile;
267 var file = dir.createFile(entry.name, .{ .exclusive = true }) catch |e| {
267 var file = dir.createFile(io, entry.name, .{ .exclusive = true }) catch |e| {
268268 const file_name = try std.fs.path.join(diagnostics.allocator, &.{ current_path, entry.name });
269269 errdefer diagnostics.allocator.free(file_name);
270270 try diagnostics.errors.append(diagnostics.allocator, .{ .unable_to_create_file = .{
......@@ -1584,14 +1584,14 @@ fn runRepositoryTest(io: Io, comptime format: Oid.Format, head_commit: []const u
15841584
15851585 var git_dir = testing.tmpDir(.{});
15861586 defer git_dir.cleanup();
1587 var pack_file = try git_dir.dir.createFile("testrepo.pack", .{ .read = true });
1587 var pack_file = try git_dir.dir.createFile(io, "testrepo.pack", .{ .read = true });
15881588 defer pack_file.close(io);
15891589 try pack_file.writeAll(testrepo_pack);
15901590
15911591 var pack_file_buffer: [2000]u8 = undefined;
15921592 var pack_file_reader = pack_file.reader(io, &pack_file_buffer);
15931593
1594 var index_file = try git_dir.dir.createFile("testrepo.idx", .{ .read = true });
1594 var index_file = try git_dir.dir.createFile(io, "testrepo.idx", .{ .read = true });
15951595 defer index_file.close(io);
15961596 var index_file_buffer: [2000]u8 = undefined;
15971597 var index_file_writer = index_file.writer(&index_file_buffer);
......@@ -1714,20 +1714,20 @@ pub fn main() !void {
17141714
17151715 const format = std.meta.stringToEnum(Oid.Format, args[1]) orelse return error.InvalidFormat;
17161716
1717 var pack_file = try std.fs.cwd().openFile(io, args[2], .{});
1717 var pack_file = try Io.Dir.cwd().openFile(io, args[2], .{});
17181718 defer pack_file.close(io);
17191719 var pack_file_buffer: [4096]u8 = undefined;
17201720 var pack_file_reader = pack_file.reader(io, &pack_file_buffer);
17211721
17221722 const commit = try Oid.parse(format, args[3]);
1723 var worktree = try std.fs.cwd().makeOpenPath(args[4], .{});
1723 var worktree = try Io.Dir.cwd().makeOpenPath(args[4], .{});
17241724 defer worktree.close(io);
17251725
17261726 var git_dir = try worktree.makeOpenPath(".git", .{});
17271727 defer git_dir.close(io);
17281728
17291729 std.debug.print("Starting index...\n", .{});
1730 var index_file = try git_dir.createFile("idx", .{ .read = true });
1730 var index_file = try git_dir.createFile(io, "idx", .{ .read = true });
17311731 defer index_file.close(io);
17321732 var index_file_buffer: [4096]u8 = undefined;
17331733 var index_file_writer = index_file.writer(&index_file_buffer);
src/Zcu/PerThread.zig+2-2
......@@ -170,7 +170,7 @@ pub fn updateFile(
170170 // version. Likewise if we're working on AstGen and another process asks for
171171 // the cached file, they'll get it.
172172 const cache_file = while (true) {
173 break zir_dir.createFile(&hex_digest, .{
173 break zir_dir.createFile(io, &hex_digest, .{
174174 .read = true,
175175 .truncate = false,
176176 .lock = lock,
......@@ -196,7 +196,7 @@ pub fn updateFile(
196196 cache_directory,
197197 });
198198 }
199 break zir_dir.createFile(&hex_digest, .{
199 break zir_dir.createFile(io, &hex_digest, .{
200200 .read = true,
201201 .truncate = false,
202202 .lock = lock,
src/codegen/llvm.zig+10-7
......@@ -1,19 +1,22 @@
1const std = @import("std");
21const builtin = @import("builtin");
2
3const std = @import("std");
4const Io = std.Io;
35const assert = std.debug.assert;
46const Allocator = std.mem.Allocator;
57const log = std.log.scoped(.codegen);
68const math = std.math;
79const DW = std.dwarf;
8
910const Builder = std.zig.llvm.Builder;
11
12const build_options = @import("build_options");
1013const llvm = if (build_options.have_llvm)
1114 @import("llvm/bindings.zig")
1215else
1316 @compileError("LLVM unavailable");
17
1418const link = @import("../link.zig");
1519const Compilation = @import("../Compilation.zig");
16const build_options = @import("build_options");
1720const Zcu = @import("../Zcu.zig");
1821const InternPool = @import("../InternPool.zig");
1922const Package = @import("../Package.zig");
......@@ -964,7 +967,7 @@ pub const Object = struct {
964967 if (std.mem.eql(u8, path, "-")) {
965968 o.builder.dump();
966969 } else {
967 o.builder.printToFilePath(std.fs.cwd(), path) catch |err| {
970 o.builder.printToFilePath(Io.Dir.cwd(), path) catch |err| {
968971 log.err("failed printing LLVM module to \"{s}\": {s}", .{ path, @errorName(err) });
969972 };
970973 }
......@@ -978,7 +981,7 @@ pub const Object = struct {
978981 o.builder.clearAndFree();
979982
980983 if (options.pre_bc_path) |path| {
981 var file = std.fs.cwd().createFile(path, .{}) catch |err|
984 var file = Io.Dir.cwd().createFile(io, path, .{}) catch |err|
982985 return diags.fail("failed to create '{s}': {s}", .{ path, @errorName(err) });
983986 defer file.close(io);
984987
......@@ -991,7 +994,7 @@ pub const Object = struct {
991994 options.post_ir_path == null and options.post_bc_path == null) return;
992995
993996 if (options.post_bc_path) |path| {
994 var file = std.fs.cwd().createFile(path, .{}) catch |err|
997 var file = Io.Dir.cwd().createFile(io, path, .{}) catch |err|
995998 return diags.fail("failed to create '{s}': {s}", .{ path, @errorName(err) });
996999 defer file.close(io);
9971000
......@@ -2711,7 +2714,7 @@ pub const Object = struct {
27112714 }
27122715
27132716 fn allocTypeName(o: *Object, pt: Zcu.PerThread, ty: Type) Allocator.Error![:0]const u8 {
2714 var aw: std.Io.Writer.Allocating = .init(o.gpa);
2717 var aw: Io.Writer.Allocating = .init(o.gpa);
27152718 defer aw.deinit();
27162719 ty.print(&aw.writer, pt, null) catch |err| switch (err) {
27172720 error.WriteFailed => return error.OutOfMemory,
src/fmt.zig+3-3
......@@ -182,11 +182,11 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
182182 // Mark any excluded files/directories as already seen,
183183 // so that they are skipped later during actual processing
184184 for (excluded_files.items) |file_path| {
185 const stat = fs.cwd().statFile(file_path) catch |err| switch (err) {
185 const stat = Io.Dir.cwd().statFile(file_path) catch |err| switch (err) {
186186 error.FileNotFound => continue,
187187 // On Windows, statFile does not work for directories
188188 error.IsDir => dir: {
189 var dir = try fs.cwd().openDir(file_path, .{});
189 var dir = try Io.Dir.cwd().openDir(file_path, .{});
190190 defer dir.close(io);
191191 break :dir try dir.stat();
192192 },
......@@ -196,7 +196,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
196196 }
197197
198198 for (input_files.items) |file_path| {
199 try fmtPath(&fmt, file_path, check_flag, fs.cwd(), file_path);
199 try fmtPath(&fmt, file_path, check_flag, Io.Dir.cwd(), file_path);
200200 }
201201 try fmt.stdout_writer.interface.flush();
202202 if (fmt.any_error) {
src/introspect.zig+2-2
......@@ -82,7 +82,7 @@ pub fn findZigLibDirFromSelfExe(
8282 cwd_path: []const u8,
8383 self_exe_path: []const u8,
8484) error{ OutOfMemory, FileNotFound }!Cache.Directory {
85 const cwd = fs.cwd();
85 const cwd = Io.Dir.cwd();
8686 var cur_path: []const u8 = self_exe_path;
8787 while (fs.path.dirname(cur_path)) |dirname| : (cur_path = dirname) {
8888 var base_dir = cwd.openDir(dirname, .{}) catch continue;
......@@ -206,7 +206,7 @@ pub fn resolveSuitableLocalCacheDir(arena: Allocator, cwd: []const u8) Allocator
206206 var cur_dir = cwd;
207207 while (true) {
208208 const joined = try fs.path.join(arena, &.{ cur_dir, Package.build_zig_basename });
209 if (fs.cwd().access(joined, .{})) |_| {
209 if (Io.Dir.cwd().access(joined, .{})) |_| {
210210 return try fs.path.join(arena, &.{ cur_dir, default_local_zig_cache_basename });
211211 } else |err| switch (err) {
212212 error.FileNotFound => {
src/libs/freebsd.zig+6-6
......@@ -1,9 +1,9 @@
11const std = @import("std");
2const Io = std.Io;
23const Allocator = std.mem.Allocator;
34const mem = std.mem;
45const log = std.log;
5const fs = std.fs;
6const path = fs.path;
6const path = std.Io.Dir.path;
77const assert = std.debug.assert;
88const Version = std.SemanticVersion;
99const Path = std.Build.Cache.Path;
......@@ -446,7 +446,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
446446 .io = io,
447447 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
448448 };
449 cache.addPrefix(.{ .path = null, .handle = fs.cwd() });
449 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
450450 cache.addPrefix(comp.dirs.zig_lib);
451451 cache.addPrefix(comp.dirs.global_cache);
452452 defer cache.manifest_dir.close(io);
......@@ -468,7 +468,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
468468 .lock = man.toOwnedLock(),
469469 .dir_path = .{
470470 .root_dir = comp.dirs.global_cache,
471 .sub_path = try gpa.dupe(u8, "o" ++ fs.path.sep_str ++ digest),
471 .sub_path = try gpa.dupe(u8, "o" ++ path.sep_str ++ digest),
472472 },
473473 });
474474 }
......@@ -986,7 +986,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
986986 .lock = man.toOwnedLock(),
987987 .dir_path = .{
988988 .root_dir = comp.dirs.global_cache,
989 .sub_path = try gpa.dupe(u8, "o" ++ fs.path.sep_str ++ digest),
989 .sub_path = try gpa.dupe(u8, "o" ++ path.sep_str ++ digest),
990990 },
991991 });
992992}
......@@ -1014,7 +1014,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) std.Io.C
10141014 const so_path: Path = .{
10151015 .root_dir = so_files.dir_path.root_dir,
10161016 .sub_path = std.fmt.allocPrint(comp.arena, "{s}{c}lib{s}.so.{d}", .{
1017 so_files.dir_path.sub_path, fs.path.sep, lib.name, lib.getSoVersion(&target.os),
1017 so_files.dir_path.sub_path, path.sep, lib.name, lib.getSoVersion(&target.os),
10181018 }) catch return comp.setAllocFailure(),
10191019 };
10201020 task_buffer[task_buffer_i] = .{ .load_dso = so_path };
src/libs/glibc.zig+8-8
......@@ -1,9 +1,9 @@
11const std = @import("std");
2const Io = std.Io;
23const Allocator = std.mem.Allocator;
34const mem = std.mem;
45const log = std.log;
5const fs = std.fs;
6const path = fs.path;
6const path = std.Io.Dir.path;
77const assert = std.debug.assert;
88const Version = std.SemanticVersion;
99const Path = std.Build.Cache.Path;
......@@ -681,7 +681,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
681681 .io = io,
682682 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
683683 };
684 cache.addPrefix(.{ .path = null, .handle = fs.cwd() });
684 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
685685 cache.addPrefix(comp.dirs.zig_lib);
686686 cache.addPrefix(comp.dirs.global_cache);
687687 defer cache.manifest_dir.close(io);
......@@ -703,7 +703,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
703703 .lock = man.toOwnedLock(),
704704 .dir_path = .{
705705 .root_dir = comp.dirs.global_cache,
706 .sub_path = try gpa.dupe(u8, "o" ++ fs.path.sep_str ++ digest),
706 .sub_path = try gpa.dupe(u8, "o" ++ path.sep_str ++ digest),
707707 },
708708 });
709709 }
......@@ -775,7 +775,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
775775 try stubs_asm.appendSlice(".text\n");
776776
777777 var sym_i: usize = 0;
778 var sym_name_buf: std.Io.Writer.Allocating = .init(arena);
778 var sym_name_buf: Io.Writer.Allocating = .init(arena);
779779 var opt_symbol_name: ?[]const u8 = null;
780780 var versions_buffer: [32]u8 = undefined;
781781 var versions_len: usize = undefined;
......@@ -796,7 +796,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
796796 // twice, which causes a "duplicate symbol" assembler error.
797797 var versions_written = std.AutoArrayHashMap(Version, void).init(arena);
798798
799 var inc_reader: std.Io.Reader = .fixed(metadata.inclusions);
799 var inc_reader: Io.Reader = .fixed(metadata.inclusions);
800800
801801 const fn_inclusions_len = try inc_reader.takeInt(u16, .little);
802802
......@@ -1130,7 +1130,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
11301130 .lock = man.toOwnedLock(),
11311131 .dir_path = .{
11321132 .root_dir = comp.dirs.global_cache,
1133 .sub_path = try gpa.dupe(u8, "o" ++ fs.path.sep_str ++ digest),
1133 .sub_path = try gpa.dupe(u8, "o" ++ path.sep_str ++ digest),
11341134 },
11351135 });
11361136}
......@@ -1156,7 +1156,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) std.Io.C
11561156 const so_path: Path = .{
11571157 .root_dir = so_files.dir_path.root_dir,
11581158 .sub_path = std.fmt.allocPrint(comp.arena, "{s}{c}lib{s}.so.{d}", .{
1159 so_files.dir_path.sub_path, fs.path.sep, lib.name, lib.sover,
1159 so_files.dir_path.sub_path, path.sep, lib.name, lib.sover,
11601160 }) catch return comp.setAllocFailure(),
11611161 };
11621162 task_buffer[task_buffer_i] = .{ .load_dso = so_path };
src/libs/mingw.zig+9-8
......@@ -1,7 +1,8 @@
11const std = @import("std");
2const Io = std.Io;
23const Allocator = std.mem.Allocator;
34const mem = std.mem;
4const path = std.fs.path;
5const path = std.Io.Dir.path;
56const assert = std.debug.assert;
67const log = std.log.scoped(.mingw);
78
......@@ -259,7 +260,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
259260 .io = io,
260261 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
261262 };
262 cache.addPrefix(.{ .path = null, .handle = std.fs.cwd() });
263 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
263264 cache.addPrefix(comp.dirs.zig_lib);
264265 cache.addPrefix(comp.dirs.global_cache);
265266 defer cache.manifest_dir.close(io);
......@@ -304,7 +305,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
304305 .output = .{ .to_list = .{ .arena = .init(gpa) } },
305306 };
306307 defer diagnostics.deinit();
307 var aro_comp = aro.Compilation.init(gpa, arena, io, &diagnostics, std.fs.cwd());
308 var aro_comp = aro.Compilation.init(gpa, arena, io, &diagnostics, Io.Dir.cwd());
308309 defer aro_comp.deinit();
309310
310311 aro_comp.target = .fromZigTarget(target.*);
......@@ -343,7 +344,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
343344 }
344345
345346 const members = members: {
346 var aw: std.Io.Writer.Allocating = .init(gpa);
347 var aw: Io.Writer.Allocating = .init(gpa);
347348 errdefer aw.deinit();
348349 try pp.prettyPrintTokens(&aw.writer, .result_only);
349350
......@@ -376,7 +377,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
376377 errdefer gpa.free(lib_final_path);
377378
378379 {
379 const lib_final_file = try o_dir.createFile(final_lib_basename, .{ .truncate = true });
380 const lib_final_file = try o_dir.createFile(io, final_lib_basename, .{ .truncate = true });
380381 defer lib_final_file.close(io);
381382 var buffer: [1024]u8 = undefined;
382383 var file_writer = lib_final_file.writer(&buffer);
......@@ -442,7 +443,7 @@ fn findDef(
442443 } else {
443444 try override_path.print(fmt_path, .{ lib_path, lib_name });
444445 }
445 if (std.fs.cwd().access(override_path.items, .{})) |_| {
446 if (Io.Dir.cwd().access(override_path.items, .{})) |_| {
446447 return override_path.toOwnedSlice();
447448 } else |err| switch (err) {
448449 error.FileNotFound => {},
......@@ -459,7 +460,7 @@ fn findDef(
459460 } else {
460461 try override_path.print(fmt_path, .{lib_name});
461462 }
462 if (std.fs.cwd().access(override_path.items, .{})) |_| {
463 if (Io.Dir.cwd().access(override_path.items, .{})) |_| {
463464 return override_path.toOwnedSlice();
464465 } else |err| switch (err) {
465466 error.FileNotFound => {},
......@@ -476,7 +477,7 @@ fn findDef(
476477 } else {
477478 try override_path.print(fmt_path, .{lib_name});
478479 }
479 if (std.fs.cwd().access(override_path.items, .{})) |_| {
480 if (Io.Dir.cwd().access(override_path.items, .{})) |_| {
480481 return override_path.toOwnedSlice();
481482 } else |err| switch (err) {
482483 error.FileNotFound => {},
src/libs/netbsd.zig+6-6
......@@ -1,9 +1,9 @@
11const std = @import("std");
2const Io = std.Io;
23const Allocator = std.mem.Allocator;
34const mem = std.mem;
45const log = std.log;
5const fs = std.fs;
6const path = fs.path;
6const path = std.Io.Dir.path;
77const assert = std.debug.assert;
88const Version = std.SemanticVersion;
99const Path = std.Build.Cache.Path;
......@@ -387,7 +387,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
387387 .io = io,
388388 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
389389 };
390 cache.addPrefix(.{ .path = null, .handle = fs.cwd() });
390 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
391391 cache.addPrefix(comp.dirs.zig_lib);
392392 cache.addPrefix(comp.dirs.global_cache);
393393 defer cache.manifest_dir.close(io);
......@@ -409,7 +409,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
409409 .lock = man.toOwnedLock(),
410410 .dir_path = .{
411411 .root_dir = comp.dirs.global_cache,
412 .sub_path = try gpa.dupe(u8, "o" ++ fs.path.sep_str ++ digest),
412 .sub_path = try gpa.dupe(u8, "o" ++ path.sep_str ++ digest),
413413 },
414414 });
415415 }
......@@ -640,7 +640,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
640640 .lock = man.toOwnedLock(),
641641 .dir_path = .{
642642 .root_dir = comp.dirs.global_cache,
643 .sub_path = try gpa.dupe(u8, "o" ++ fs.path.sep_str ++ digest),
643 .sub_path = try gpa.dupe(u8, "o" ++ path.sep_str ++ digest),
644644 },
645645 });
646646}
......@@ -661,7 +661,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) std.Io.C
661661 const so_path: Path = .{
662662 .root_dir = so_files.dir_path.root_dir,
663663 .sub_path = std.fmt.allocPrint(comp.arena, "{s}{c}lib{s}.so.{d}", .{
664 so_files.dir_path.sub_path, fs.path.sep, lib.name, lib.sover,
664 so_files.dir_path.sub_path, path.sep, lib.name, lib.sover,
665665 }) catch return comp.setAllocFailure(),
666666 };
667667 task_buffer[task_buffer_i] = .{ .load_dso = so_path };
src/link/C.zig+2-2
......@@ -136,7 +136,7 @@ pub fn createEmpty(
136136 assert(!use_lld);
137137 assert(!use_llvm);
138138
139 const file = try emit.root_dir.handle.createFile(emit.sub_path, .{
139 const file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{
140140 // Truncation is done on `flush`.
141141 .truncate = false,
142142 });
......@@ -792,7 +792,7 @@ pub fn flushEmitH(zcu: *Zcu) !void {
792792 }
793793
794794 const directory = emit_h.loc.directory orelse zcu.comp.local_cache_directory;
795 const file = try directory.handle.createFile(emit_h.loc.basename, .{
795 const file = try directory.handle.createFile(io, emit_h.loc.basename, .{
796796 // We set the end position explicitly below; by not truncating the file, we possibly
797797 // make it easier on the file system by doing 1 reallocation instead of two.
798798 .truncate = false,
src/link/Coff.zig+4-2
......@@ -631,12 +631,14 @@ fn create(
631631 else => return error.UnsupportedCOFFArchitecture,
632632 };
633633
634 const io = comp.io;
635
634636 const coff = try arena.create(Coff);
635 const file = try path.root_dir.handle.createFile(comp.io, path.sub_path, .{
637 const file = try path.root_dir.handle.createFile(io, path.sub_path, .{
636638 .read = true,
637639 .mode = link.File.determineMode(comp.config.output_mode, comp.config.link_mode),
638640 });
639 errdefer file.close(comp.io);
641 errdefer file.close(io);
640642 coff.* = .{
641643 .base = .{
642644 .tag = .coff2,
src/link/Elf.zig+3-1
......@@ -313,9 +313,11 @@ pub fn createEmpty(
313313 const is_obj = output_mode == .Obj;
314314 const is_obj_or_ar = is_obj or (output_mode == .Lib and link_mode == .static);
315315
316 const io = comp.io;
317
316318 // What path should this ELF linker code output to?
317319 const sub_path = emit.sub_path;
318 self.base.file = try emit.root_dir.handle.createFile(sub_path, .{
320 self.base.file = try emit.root_dir.handle.createFile(io, sub_path, .{
319321 .truncate = true,
320322 .read = true,
321323 .mode = link.File.determineMode(output_mode, link_mode),
src/link/Lld.zig+2-2
......@@ -1572,7 +1572,7 @@ fn wasmLink(lld: *Lld, arena: Allocator) !void {
15721572 // report a nice error here with the file path if it fails instead of
15731573 // just returning the error code.
15741574 // chmod does not interact with umask, so we use a conservative -rwxr--r-- here.
1575 std.posix.fchmodat(fs.cwd().fd, full_out_path, 0o744, 0) catch |err| switch (err) {
1575 std.posix.fchmodat(Io.Dir.cwd().handle, full_out_path, 0o744, 0) catch |err| switch (err) {
15761576 error.OperationNotSupported => unreachable, // Not a symlink.
15771577 else => |e| return e,
15781578 };
......@@ -1624,7 +1624,7 @@ fn spawnLld(comp: *Compilation, arena: Allocator, argv: []const []const u8) !voi
16241624 const rand_int = std.crypto.random.int(u64);
16251625 const rsp_path = "tmp" ++ s ++ std.fmt.hex(rand_int) ++ ".rsp";
16261626
1627 const rsp_file = try comp.dirs.local_cache.handle.createFile(rsp_path, .{});
1627 const rsp_file = try comp.dirs.local_cache.handle.createFile(io, rsp_path, .{});
16281628 defer comp.dirs.local_cache.handle.deleteFileZ(rsp_path) catch |err|
16291629 log.warn("failed to delete response file {s}: {s}", .{ rsp_path, @errorName(err) });
16301630 {
src/link/MachO.zig+8-6
......@@ -219,7 +219,9 @@ pub fn createEmpty(
219219 };
220220 errdefer self.base.destroy();
221221
222 self.base.file = try emit.root_dir.handle.createFile(emit.sub_path, .{
222 const io = comp.io;
223
224 self.base.file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{
223225 .truncate = true,
224226 .read = true,
225227 .mode = link.File.determineMode(output_mode, link_mode),
......@@ -1082,7 +1084,7 @@ fn accessLibPath(
10821084 test_path.clearRetainingCapacity();
10831085 try test_path.print("{s}" ++ sep ++ "lib{s}{s}", .{ search_dir, name, ext });
10841086 try checked_paths.append(try arena.dupe(u8, test_path.items));
1085 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
1087 Io.Dir.cwd().access(test_path.items, .{}) catch |err| switch (err) {
10861088 error.FileNotFound => continue,
10871089 else => |e| return e,
10881090 };
......@@ -1110,7 +1112,7 @@ fn accessFrameworkPath(
11101112 ext,
11111113 });
11121114 try checked_paths.append(try arena.dupe(u8, test_path.items));
1113 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
1115 Io.Dir.cwd().access(test_path.items, .{}) catch |err| switch (err) {
11141116 error.FileNotFound => continue,
11151117 else => |e| return e,
11161118 };
......@@ -1191,7 +1193,7 @@ fn parseDependentDylibs(self: *MachO) !void {
11911193 try test_path.print("{s}{s}", .{ path, ext });
11921194 }
11931195 try checked_paths.append(try arena.dupe(u8, test_path.items));
1194 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
1196 Io.Dir.cwd().access(test_path.items, .{}) catch |err| switch (err) {
11951197 error.FileNotFound => continue,
11961198 else => |e| return e,
11971199 };
......@@ -3289,7 +3291,7 @@ pub fn reopenDebugInfo(self: *MachO) !void {
32893291 var d_sym_bundle = try self.base.emit.root_dir.handle.makeOpenPath(d_sym_path, .{});
32903292 defer d_sym_bundle.close(io);
32913293
3292 self.d_sym.?.file = try d_sym_bundle.createFile(fs.path.basename(self.base.emit.sub_path), .{
3294 self.d_sym.?.file = try d_sym_bundle.createFile(io, fs.path.basename(self.base.emit.sub_path), .{
32933295 .truncate = false,
32943296 .read = true,
32953297 });
......@@ -4370,7 +4372,7 @@ fn inferSdkVersion(comp: *Compilation, sdk_layout: SdkLayout) ?std.SemanticVersi
43704372// The file/property is also available with vendored libc.
43714373fn readSdkVersionFromSettings(arena: Allocator, dir: []const u8) ![]const u8 {
43724374 const sdk_path = try fs.path.join(arena, &.{ dir, "SDKSettings.json" });
4373 const contents = try fs.cwd().readFileAlloc(sdk_path, arena, .limited(std.math.maxInt(u16)));
4375 const contents = try Io.Dir.cwd().readFileAlloc(sdk_path, arena, .limited(std.math.maxInt(u16)));
43744376 const parsed = try std.json.parseFromSlice(std.json.Value, arena, contents, .{});
43754377 if (parsed.value.object.get("MinimalDisplayName")) |ver| return ver.string;
43764378 return error.SdkVersionFailure;
src/link/MachO/CodeSignature.zig+1-1
......@@ -247,7 +247,7 @@ pub fn deinit(self: *CodeSignature, allocator: Allocator) void {
247247}
248248
249249pub fn addEntitlements(self: *CodeSignature, allocator: Allocator, path: []const u8) !void {
250 const inner = try fs.cwd().readFileAlloc(path, allocator, .limited(std.math.maxInt(u32)));
250 const inner = try Io.Dir.cwd().readFileAlloc(path, allocator, .limited(std.math.maxInt(u32)));
251251 self.entitlements = .{ .inner = inner };
252252}
253253
src/link/SpirV.zig+2-1
......@@ -33,6 +33,7 @@ pub fn createEmpty(
3333 options: link.File.OpenOptions,
3434) !*Linker {
3535 const gpa = comp.gpa;
36 const io = comp.io;
3637 const target = &comp.root_mod.resolved_target.result;
3738
3839 assert(!comp.config.use_lld); // Caught by Compilation.Config.resolve
......@@ -78,7 +79,7 @@ pub fn createEmpty(
7879 };
7980 errdefer linker.deinit();
8081
81 linker.base.file = try emit.root_dir.handle.createFile(emit.sub_path, .{
82 linker.base.file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{
8283 .truncate = true,
8384 .read = true,
8485 });
src/link/Wasm.zig+3-1
......@@ -2997,7 +2997,9 @@ pub fn createEmpty(
29972997 .named => |name| (try wasm.internString(name)).toOptional(),
29982998 };
29992999
3000 wasm.base.file = try emit.root_dir.handle.createFile(emit.sub_path, .{
3000 const io = comp.io;
3001
3002 wasm.base.file = try emit.root_dir.handle.createFile(io, emit.sub_path, .{
30013003 .truncate = true,
30023004 .read = true,
30033005 .mode = if (fs.has_executable_bit)
src/main.zig+18-18
......@@ -713,7 +713,7 @@ const Emit = union(enum) {
713713 } else e: {
714714 // If there's a dirname, check that dir exists. This will give a more descriptive error than `Compilation` otherwise would.
715715 if (fs.path.dirname(path)) |dir_path| {
716 var dir = fs.cwd().openDir(dir_path, .{}) catch |err| {
716 var dir = Io.Dir.cwd().openDir(dir_path, .{}) catch |err| {
717717 fatal("unable to open output directory '{s}': {s}", .{ dir_path, @errorName(err) });
718718 };
719719 dir.close(io);
......@@ -3304,7 +3304,7 @@ fn buildOutputType(
33043304 } else emit: {
33053305 // If there's a dirname, check that dir exists. This will give a more descriptive error than `Compilation` otherwise would.
33063306 if (fs.path.dirname(path)) |dir_path| {
3307 var dir = fs.cwd().openDir(dir_path, .{}) catch |err| {
3307 var dir = Io.Dir.cwd().openDir(dir_path, .{}) catch |err| {
33083308 fatal("unable to open output directory '{s}': {s}", .{ dir_path, @errorName(err) });
33093309 };
33103310 dir.close(io);
......@@ -3389,7 +3389,7 @@ fn buildOutputType(
33893389 // file will not run and this temp file will be leaked. The filename
33903390 // will be a hash of its contents — so multiple invocations of
33913391 // `zig cc -` will result in the same temp file name.
3392 var f = try dirs.local_cache.handle.createFile(dump_path, .{});
3392 var f = try dirs.local_cache.handle.createFile(io, dump_path, .{});
33933393 defer f.close(io);
33943394
33953395 // Re-using the hasher from Cache, since the functional requirements
......@@ -4773,7 +4773,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
47734773 var ok_count: usize = 0;
47744774
47754775 for (template_paths) |template_path| {
4776 if (templates.write(arena, fs.cwd(), sanitized_root_name, template_path, fingerprint)) |_| {
4776 if (templates.write(arena, Io.Dir.cwd(), sanitized_root_name, template_path, fingerprint)) |_| {
47774777 std.log.info("created {s}", .{template_path});
47784778 ok_count += 1;
47794779 } else |err| switch (err) {
......@@ -5227,7 +5227,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
52275227 if (system_pkg_dir_path) |p| {
52285228 job_queue.global_cache = .{
52295229 .path = p,
5230 .handle = fs.cwd().openDir(p, .{}) catch |err| {
5230 .handle = Io.Dir.cwd().openDir(p, .{}) catch |err| {
52315231 fatal("unable to open system package directory '{s}': {s}", .{
52325232 p, @errorName(err),
52335233 });
......@@ -5823,7 +5823,7 @@ const ArgIteratorResponseFile = process.ArgIteratorGeneral(.{ .comments = true,
58235823/// Initialize the arguments from a Response File. "*.rsp"
58245824fn initArgIteratorResponseFile(allocator: Allocator, resp_file_path: []const u8) !ArgIteratorResponseFile {
58255825 const max_bytes = 10 * 1024 * 1024; // 10 MiB of command line arguments is a reasonable limit
5826 const cmd_line = try fs.cwd().readFileAlloc(resp_file_path, allocator, .limited(max_bytes));
5826 const cmd_line = try Io.Dir.cwd().readFileAlloc(resp_file_path, allocator, .limited(max_bytes));
58275827 errdefer allocator.free(cmd_line);
58285828
58295829 return ArgIteratorResponseFile.initTakeOwnership(allocator, cmd_line);
......@@ -6187,7 +6187,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
61876187 const display_path = zig_source_path orelse "<stdin>";
61886188 const source: [:0]const u8 = s: {
61896189 var f = if (zig_source_path) |p| file: {
6190 break :file fs.cwd().openFile(io, p, .{}) catch |err| {
6190 break :file Io.Dir.cwd().openFile(io, p, .{}) catch |err| {
61916191 fatal("unable to open file '{s}' for ast-check: {s}", .{ display_path, @errorName(err) });
61926192 };
61936193 } else Io.File.stdin();
......@@ -6494,7 +6494,7 @@ fn cmdDumpZir(arena: Allocator, io: Io, args: []const []const u8) !void {
64946494
64956495 const cache_file = args[0];
64966496
6497 var f = fs.cwd().openFile(io, cache_file, .{}) catch |err| {
6497 var f = Io.Dir.cwd().openFile(io, cache_file, .{}) catch |err| {
64986498 fatal("unable to open zir cache file for dumping '{s}': {s}", .{ cache_file, @errorName(err) });
64996499 };
65006500 defer f.close(io);
......@@ -6541,7 +6541,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {
65416541 const new_source_path = args[1];
65426542
65436543 const old_source = source: {
6544 var f = fs.cwd().openFile(io, old_source_path, .{}) catch |err|
6544 var f = Io.Dir.cwd().openFile(io, old_source_path, .{}) catch |err|
65456545 fatal("unable to open old source file '{s}': {s}", .{ old_source_path, @errorName(err) });
65466546 defer f.close(io);
65476547 var file_reader: Io.File.Reader = f.reader(io, &stdin_buffer);
......@@ -6549,7 +6549,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {
65496549 fatal("unable to read old source file '{s}': {s}", .{ old_source_path, @errorName(err) });
65506550 };
65516551 const new_source = source: {
6552 var f = fs.cwd().openFile(io, new_source_path, .{}) catch |err|
6552 var f = Io.Dir.cwd().openFile(io, new_source_path, .{}) catch |err|
65536553 fatal("unable to open new source file '{s}': {s}", .{ new_source_path, @errorName(err) });
65546554 defer f.close(io);
65556555 var file_reader: Io.File.Reader = f.reader(io, &stdin_buffer);
......@@ -6845,7 +6845,7 @@ fn accessFrameworkPath(
68456845 framework_dir_path, framework_name, framework_name, ext,
68466846 });
68476847 try checked_paths.print("\n {s}", .{test_path.items});
6848 fs.cwd().access(test_path.items, .{}) catch |err| switch (err) {
6848 Io.Dir.cwd().access(test_path.items, .{}) catch |err| switch (err) {
68496849 error.FileNotFound => continue,
68506850 else => |e| fatal("unable to search for {s} framework '{s}': {s}", .{
68516851 ext, test_path.items, @errorName(e),
......@@ -6957,7 +6957,7 @@ fn cmdFetch(
69576957 var global_cache_directory: Directory = l: {
69586958 const p = override_global_cache_dir orelse try introspect.resolveGlobalCacheDir(arena);
69596959 break :l .{
6960 .handle = try fs.cwd().makeOpenPath(p, .{}),
6960 .handle = try Io.Dir.cwd().makeOpenPath(p, .{}),
69616961 .path = p,
69626962 };
69636963 };
......@@ -7260,7 +7260,7 @@ fn findBuildRoot(arena: Allocator, options: FindBuildRootOptions) !BuildRoot {
72607260
72617261 if (options.build_file) |bf| {
72627262 if (fs.path.dirname(bf)) |dirname| {
7263 const dir = fs.cwd().openDir(dirname, .{}) catch |err| {
7263 const dir = Io.Dir.cwd().openDir(dirname, .{}) catch |err| {
72647264 fatal("unable to open directory to build file from argument 'build-file', '{s}': {s}", .{ dirname, @errorName(err) });
72657265 };
72667266 return .{
......@@ -7272,7 +7272,7 @@ fn findBuildRoot(arena: Allocator, options: FindBuildRootOptions) !BuildRoot {
72727272
72737273 return .{
72747274 .build_zig_basename = build_zig_basename,
7275 .directory = .{ .path = null, .handle = fs.cwd() },
7275 .directory = .{ .path = null, .handle = Io.Dir.cwd() },
72767276 .cleanup_build_dir = null,
72777277 };
72787278 }
......@@ -7280,8 +7280,8 @@ fn findBuildRoot(arena: Allocator, options: FindBuildRootOptions) !BuildRoot {
72807280 var dirname: []const u8 = cwd_path;
72817281 while (true) {
72827282 const joined_path = try fs.path.join(arena, &[_][]const u8{ dirname, build_zig_basename });
7283 if (fs.cwd().access(joined_path, .{})) |_| {
7284 const dir = fs.cwd().openDir(dirname, .{}) catch |err| {
7283 if (Io.Dir.cwd().access(joined_path, .{})) |_| {
7284 const dir = Io.Dir.cwd().openDir(dirname, .{}) catch |err| {
72857285 fatal("unable to open directory while searching for build.zig file, '{s}': {s}", .{ dirname, @errorName(err) });
72867286 };
72877287 return .{
......@@ -7443,7 +7443,7 @@ const Templates = struct {
74437443 }
74447444};
74457445fn writeSimpleTemplateFile(io: Io, file_name: []const u8, comptime fmt: []const u8, args: anytype) !void {
7446 const f = try fs.cwd().createFile(file_name, .{ .exclusive = true });
7446 const f = try Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true });
74477447 defer f.close(io);
74487448 var buf: [4096]u8 = undefined;
74497449 var fw = f.writer(&buf);
......@@ -7591,7 +7591,7 @@ fn addLibDirectoryWarn2(
75917591 ignore_not_found: bool,
75927592) void {
75937593 lib_directories.appendAssumeCapacity(.{
7594 .handle = fs.cwd().openDir(path, .{}) catch |err| {
7594 .handle = Io.Dir.cwd().openDir(path, .{}) catch |err| {
75957595 if (err == error.FileNotFound and ignore_not_found) return;
75967596 warn("unable to open library directory '{s}': {s}", .{ path, @errorName(err) });
75977597 return;