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" {...@@ -2253,7 +2253,7 @@ test "addSourceFromBuffer" {
2253 var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);2253 var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
2254 defer arena.deinit();2254 defer arena.deinit();
2255 var diagnostics: Diagnostics = .{ .output = .ignore };2255 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());
2257 defer comp.deinit();2257 defer comp.deinit();
22582258
2259 const source = try comp.addSourceFromBuffer("path", str);2259 const source = try comp.addSourceFromBuffer("path", str);
...@@ -2267,7 +2267,7 @@ test "addSourceFromBuffer" {...@@ -2267,7 +2267,7 @@ test "addSourceFromBuffer" {
2267 var arena: std.heap.ArenaAllocator = .init(allocator);2267 var arena: std.heap.ArenaAllocator = .init(allocator);
2268 defer arena.deinit();2268 defer arena.deinit();
2269 var diagnostics: Diagnostics = .{ .output = .ignore };2269 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());
2271 defer comp.deinit();2271 defer comp.deinit();
22722272
2273 _ = try comp.addSourceFromBuffer("path", "spliced\\\nbuffer\n");2273 _ = try comp.addSourceFromBuffer("path", "spliced\\\nbuffer\n");
...@@ -2313,7 +2313,7 @@ test "addSourceFromBuffer - exhaustive check for carriage return elimination" {...@@ -2313,7 +2313,7 @@ test "addSourceFromBuffer - exhaustive check for carriage return elimination" {
2313 var buf: [alphabet.len]u8 = @splat(alphabet[0]);2313 var buf: [alphabet.len]u8 = @splat(alphabet[0]);
23142314
2315 var diagnostics: Diagnostics = .{ .output = .ignore };2315 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());
2317 defer comp.deinit();2317 defer comp.deinit();
23182318
2319 var source_count: u32 = 0;2319 var source_count: u32 = 0;
...@@ -2341,7 +2341,7 @@ test "ignore BOM at beginning of file" {...@@ -2341,7 +2341,7 @@ test "ignore BOM at beginning of file" {
2341 const Test = struct {2341 const Test = struct {
2342 fn run(arena: Allocator, buf: []const u8) !void {2342 fn run(arena: Allocator, buf: []const u8) !void {
2343 var diagnostics: Diagnostics = .{ .output = .ignore };2343 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());
2345 defer comp.deinit();2345 defer comp.deinit();
23462346
2347 const source = try comp.addSourceFromBuffer("file.c", buf);2347 const source = try comp.addSourceFromBuffer("file.c", buf);
lib/compiler/aro/aro/Driver.zig+5-5
...@@ -1327,7 +1327,7 @@ fn processSource(...@@ -1327,7 +1327,7 @@ fn processSource(
1327 const dep_file_name = try d.getDepFileName(source, writer_buf[0..std.fs.max_name_bytes]);1327 const dep_file_name = try d.getDepFileName(source, writer_buf[0..std.fs.max_name_bytes]);
13281328
1329 const file = if (dep_file_name) |path|1329 const file = if (dep_file_name) |path|
1330 d.comp.cwd.createFile(path, .{}) catch |er|1330 d.comp.cwd.createFile(io, path, .{}) catch |er|
1331 return d.fatal("unable to create dependency file '{s}': {s}", .{ path, errorDescription(er) })1331 return d.fatal("unable to create dependency file '{s}': {s}", .{ path, errorDescription(er) })
1332 else1332 else
1333 Io.File.stdout();1333 Io.File.stdout();
...@@ -1352,7 +1352,7 @@ fn processSource(...@@ -1352,7 +1352,7 @@ fn processSource(
1352 }1352 }
13531353
1354 const file = if (d.output_name) |some|1354 const file = if (d.output_name) |some|
1355 d.comp.cwd.createFile(some, .{}) catch |er|1355 d.comp.cwd.createFile(io, some, .{}) catch |er|
1356 return d.fatal("unable to create output file '{s}': {s}", .{ some, errorDescription(er) })1356 return d.fatal("unable to create output file '{s}': {s}", .{ some, errorDescription(er) })
1357 else1357 else
1358 Io.File.stdout();1358 Io.File.stdout();
...@@ -1405,7 +1405,7 @@ fn processSource(...@@ -1405,7 +1405,7 @@ fn processSource(
1405 defer assembly.deinit(gpa);1405 defer assembly.deinit(gpa);
14061406
1407 if (d.only_preprocess_and_compile) {1407 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|
1409 return d.fatal("unable to create output file '{s}': {s}", .{ out_file_name, errorDescription(er) });1409 return d.fatal("unable to create output file '{s}': {s}", .{ out_file_name, errorDescription(er) });
1410 defer out_file.close(io);1410 defer out_file.close(io);
14111411
...@@ -1419,7 +1419,7 @@ fn processSource(...@@ -1419,7 +1419,7 @@ fn processSource(
1419 // then assemble to out_file_name1419 // then assemble to out_file_name
1420 var assembly_name_buf: [std.fs.max_name_bytes]u8 = undefined;1420 var assembly_name_buf: [std.fs.max_name_bytes]u8 = undefined;
1421 const assembly_out_file_name = try d.getRandomFilename(&assembly_name_buf, ".s");1421 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|
1423 return d.fatal("unable to create output file '{s}': {s}", .{ assembly_out_file_name, errorDescription(er) });1423 return d.fatal("unable to create output file '{s}': {s}", .{ assembly_out_file_name, errorDescription(er) });
1424 defer out_file.close(io);1424 defer out_file.close(io);
1425 assembly.writeToFile(out_file) catch |er|1425 assembly.writeToFile(out_file) catch |er|
...@@ -1455,7 +1455,7 @@ fn processSource(...@@ -1455,7 +1455,7 @@ fn processSource(
1455 };1455 };
1456 defer obj.deinit();1456 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|
1459 return d.fatal("unable to create output file '{s}': {s}", .{ out_file_name, errorDescription(er) });1459 return d.fatal("unable to create output file '{s}': {s}", .{ out_file_name, errorDescription(er) });
1460 defer out_file.close(io);1460 defer out_file.close(io);
14611461
lib/compiler/aro/aro/Parser.zig+14-13
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const mem = std.mem;3const mem = std.mem;
3const Allocator = mem.Allocator;4const Allocator = mem.Allocator;
4const assert = std.debug.assert;5const assert = std.debug.assert;
...@@ -211,7 +212,7 @@ fn checkIdentifierCodepointWarnings(p: *Parser, codepoint: u21, loc: Source.Loca...@@ -211,7 +212,7 @@ fn checkIdentifierCodepointWarnings(p: *Parser, codepoint: u21, loc: Source.Loca
211212
212 const prev_total = p.diagnostics.total;213 const prev_total = p.diagnostics.total;
213 var sf = std.heap.stackFallback(1024, p.comp.gpa);214 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());
215 defer allocating.deinit();216 defer allocating.deinit();
216217
217 if (!char_info.isC99IdChar(codepoint)) {218 if (!char_info.isC99IdChar(codepoint)) {
...@@ -425,7 +426,7 @@ pub fn err(p: *Parser, tok_i: TokenIndex, diagnostic: Diagnostic, args: anytype)...@@ -425,7 +426,7 @@ pub fn err(p: *Parser, tok_i: TokenIndex, diagnostic: Diagnostic, args: anytype)
425 if (p.diagnostics.effectiveKind(diagnostic) == .off) return;426 if (p.diagnostics.effectiveKind(diagnostic) == .off) return;
426427
427 var sf = std.heap.stackFallback(1024, p.comp.gpa);428 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());
429 defer allocating.deinit();430 defer allocating.deinit();
430431
431 p.formatArgs(&allocating.writer, diagnostic.fmt, args) catch return error.OutOfMemory;432 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)...@@ -447,7 +448,7 @@ pub fn err(p: *Parser, tok_i: TokenIndex, diagnostic: Diagnostic, args: anytype)
447 }, p.pp.expansionSlice(tok_i), true);448 }, p.pp.expansionSlice(tok_i), true);
448}449}
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 {
451 var i: usize = 0;452 var i: usize = 0;
452 inline for (std.meta.fields(@TypeOf(args))) |arg_info| {453 inline for (std.meta.fields(@TypeOf(args))) |arg_info| {
453 const arg = @field(args, arg_info.name);454 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...@@ -476,13 +477,13 @@ fn formatArgs(p: *Parser, w: *std.Io.Writer, fmt: []const u8, args: anytype) !vo
476 try w.writeAll(fmt[i..]);477 try w.writeAll(fmt[i..]);
477}478}
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 {
480 const i = Diagnostics.templateIndex(w, fmt, "{tok_id}");481 const i = Diagnostics.templateIndex(w, fmt, "{tok_id}");
481 try w.writeAll(tok_id.symbol());482 try w.writeAll(tok_id.symbol());
482 return i;483 return i;
483}484}
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 {
486 const i = Diagnostics.templateIndex(w, fmt, "{qt}");487 const i = Diagnostics.templateIndex(w, fmt, "{qt}");
487 try w.writeByte('\'');488 try w.writeByte('\'');
488 try qt.print(p.comp, w);489 try qt.print(p.comp, w);
...@@ -501,7 +502,7 @@ fn formatQualType(p: *Parser, w: *std.Io.Writer, fmt: []const u8, qt: QualType)...@@ -501,7 +502,7 @@ fn formatQualType(p: *Parser, w: *std.Io.Writer, fmt: []const u8, qt: QualType)
501 return i;502 return i;
502}503}
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 {
505 const i = Diagnostics.templateIndex(w, fmt, "{value}");506 const i = Diagnostics.templateIndex(w, fmt, "{value}");
506 switch (res.val.opt_ref) {507 switch (res.val.opt_ref) {
507 .none => try w.writeAll("(none)"),508 .none => try w.writeAll("(none)"),
...@@ -524,7 +525,7 @@ const Normalized = struct {...@@ -524,7 +525,7 @@ const Normalized = struct {
524 return .{ .str = str };525 return .{ .str = str };
525 }526 }
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 {
528 const i = Diagnostics.templateIndex(w, fmt, "{normalized}");529 const i = Diagnostics.templateIndex(w, fmt, "{normalized}");
529 var it: std.unicode.Utf8Iterator = .{530 var it: std.unicode.Utf8Iterator = .{
530 .bytes = ctx.str,531 .bytes = ctx.str,
...@@ -558,7 +559,7 @@ const Codepoint = struct {...@@ -558,7 +559,7 @@ const Codepoint = struct {
558 return .{ .codepoint = codepoint };559 return .{ .codepoint = codepoint };
559 }560 }
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 {
562 const i = Diagnostics.templateIndex(w, fmt, "{codepoint}");563 const i = Diagnostics.templateIndex(w, fmt, "{codepoint}");
563 try w.print("{X:0>4}", .{ctx.codepoint});564 try w.print("{X:0>4}", .{ctx.codepoint});
564 return i;565 return i;
...@@ -572,7 +573,7 @@ const Escaped = struct {...@@ -572,7 +573,7 @@ const Escaped = struct {
572 return .{ .str = str };573 return .{ .str = str };
573 }574 }
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 {
576 const i = Diagnostics.templateIndex(w, fmt, "{s}");577 const i = Diagnostics.templateIndex(w, fmt, "{s}");
577 try std.zig.stringEscape(ctx.str, w);578 try std.zig.stringEscape(ctx.str, w);
578 return i;579 return i;
...@@ -1453,7 +1454,7 @@ fn decl(p: *Parser) Error!bool {...@@ -1453,7 +1454,7 @@ fn decl(p: *Parser) Error!bool {
1453 return true;1454 return true;
1454}1455}
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 {
1457 const w = &allocating.writer;1458 const w = &allocating.writer;
14581459
1459 const cond = cond_node.get(&p.tree);1460 const cond = cond_node.get(&p.tree);
...@@ -1526,7 +1527,7 @@ fn staticAssert(p: *Parser) Error!bool {...@@ -1526,7 +1527,7 @@ fn staticAssert(p: *Parser) Error!bool {
1526 } else {1527 } else {
1527 if (!res.val.toBool(p.comp)) {1528 if (!res.val.toBool(p.comp)) {
1528 var sf = std.heap.stackFallback(1024, gpa);1529 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());
1530 defer allocating.deinit();1531 defer allocating.deinit();
15311532
1532 if (p.staticAssertMessage(res_node, str, &allocating) catch return error.OutOfMemory) |message| {1533 if (p.staticAssertMessage(res_node, str, &allocating) catch return error.OutOfMemory) |message| {
...@@ -9719,7 +9720,7 @@ fn primaryExpr(p: *Parser) Error!?Result {...@@ -9719,7 +9720,7 @@ fn primaryExpr(p: *Parser) Error!?Result {
9719 qt = some.qt;9720 qt = some.qt;
9720 } else if (p.func.qt) |func_qt| {9721 } else if (p.func.qt) |func_qt| {
9721 var sf = std.heap.stackFallback(1024, gpa);9722 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());
9723 defer allocating.deinit();9724 defer allocating.deinit();
97249725
9725 func_qt.printNamed(p.tokSlice(p.func.name), p.comp, &allocating.writer) catch return error.OutOfMemory;9726 func_qt.printNamed(p.tokSlice(p.func.name), p.comp, &allocating.writer) catch return error.OutOfMemory;
...@@ -10608,7 +10609,7 @@ test "Node locations" {...@@ -10608,7 +10609,7 @@ test "Node locations" {
10608 const arena = arena_state.allocator();10609 const arena = arena_state.allocator();
1060910610
10610 var diagnostics: Diagnostics = .{ .output = .ignore };10611 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());
10612 defer comp.deinit();10613 defer comp.deinit();
1061310614
10614 const file = try comp.addSourceFromBuffer("file.c",10615 const file = try comp.addSourceFromBuffer("file.c",
lib/compiler/aro/aro/Preprocessor.zig+3-3
...@@ -3900,7 +3900,7 @@ test "Preserve pragma tokens sometimes" {...@@ -3900,7 +3900,7 @@ test "Preserve pragma tokens sometimes" {
3900 defer arena.deinit();3900 defer arena.deinit();
39013901
3902 var diagnostics: Diagnostics = .{ .output = .ignore };3902 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());
3904 defer comp.deinit();3904 defer comp.deinit();
39053905
3906 try comp.addDefaultPragmaHandlers();3906 try comp.addDefaultPragmaHandlers();
...@@ -3967,7 +3967,7 @@ test "destringify" {...@@ -3967,7 +3967,7 @@ test "destringify" {
3967 var arena: std.heap.ArenaAllocator = .init(gpa);3967 var arena: std.heap.ArenaAllocator = .init(gpa);
3968 defer arena.deinit();3968 defer arena.deinit();
3969 var diagnostics: Diagnostics = .{ .output = .ignore };3969 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());
3971 defer comp.deinit();3971 defer comp.deinit();
3972 var pp = Preprocessor.init(&comp, .default);3972 var pp = Preprocessor.init(&comp, .default);
3973 defer pp.deinit();3973 defer pp.deinit();
...@@ -4030,7 +4030,7 @@ test "Include guards" {...@@ -4030,7 +4030,7 @@ test "Include guards" {
4030 const arena = arena_state.allocator();4030 const arena = arena_state.allocator();
40314031
4032 var diagnostics: Diagnostics = .{ .output = .ignore };4032 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());
4034 defer comp.deinit();4034 defer comp.deinit();
4035 var pp = Preprocessor.init(&comp, .default);4035 var pp = Preprocessor.init(&comp, .default);
4036 defer pp.deinit();4036 defer pp.deinit();
lib/compiler/aro/aro/Tokenizer.zig+3-2
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const assert = std.debug.assert;3const assert = std.debug.assert;
34
4const Compilation = @import("Compilation.zig");5const Compilation = @import("Compilation.zig");
...@@ -2326,7 +2327,7 @@ test "Tokenizer fuzz test" {...@@ -2326,7 +2327,7 @@ test "Tokenizer fuzz test" {
2326 fn testOne(_: @This(), input_bytes: []const u8) anyerror!void {2327 fn testOne(_: @This(), input_bytes: []const u8) anyerror!void {
2327 var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);2328 var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
2328 defer arena.deinit();2329 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());
2330 defer comp.deinit();2331 defer comp.deinit();
23312332
2332 const source = try comp.addSourceFromBuffer("fuzz.c", input_bytes);2333 const source = try comp.addSourceFromBuffer("fuzz.c", input_bytes);
...@@ -2351,7 +2352,7 @@ test "Tokenizer fuzz test" {...@@ -2351,7 +2352,7 @@ test "Tokenizer fuzz test" {
2351fn expectTokensExtra(contents: []const u8, expected_tokens: []const Token.Id, langopts: ?LangOpts) !void {2352fn expectTokensExtra(contents: []const u8, expected_tokens: []const Token.Id, langopts: ?LangOpts) !void {
2352 var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);2353 var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
2353 defer arena.deinit();2354 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());
2355 defer comp.deinit();2356 defer comp.deinit();
2356 if (langopts) |provided| {2357 if (langopts) |provided| {
2357 comp.langopts = provided;2358 comp.langopts = provided;
lib/compiler/aro/aro/Value.zig+6-5
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const assert = std.debug.assert;3const assert = std.debug.assert;
3const BigIntConst = std.math.big.int.Const;4const BigIntConst = std.math.big.int.Const;
4const BigIntMutable = std.math.big.int.Mutable;5const BigIntMutable = std.math.big.int.Mutable;
...@@ -80,7 +81,7 @@ test "minUnsignedBits" {...@@ -80,7 +81,7 @@ test "minUnsignedBits" {
80 defer arena_state.deinit();81 defer arena_state.deinit();
81 const arena = arena_state.allocator();82 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());
84 defer comp.deinit();85 defer comp.deinit();
85 const target_query = try std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux-gnu" });86 const target_query = try std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux-gnu" });
86 comp.target = .fromZigTarget(try std.zig.system.resolveTargetQuery(std.testing.io, target_query));87 comp.target = .fromZigTarget(try std.zig.system.resolveTargetQuery(std.testing.io, target_query));
...@@ -119,7 +120,7 @@ test "minSignedBits" {...@@ -119,7 +120,7 @@ test "minSignedBits" {
119 defer arena_state.deinit();120 defer arena_state.deinit();
120 const arena = arena_state.allocator();121 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());
123 defer comp.deinit();124 defer comp.deinit();
124 const target_query = try std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux-gnu" });125 const target_query = try std.Target.Query.parse(.{ .arch_os_abi = "x86_64-linux-gnu" });
125 comp.target = .fromZigTarget(try std.zig.system.resolveTargetQuery(std.testing.io, target_query));126 comp.target = .fromZigTarget(try std.zig.system.resolveTargetQuery(std.testing.io, target_query));
...@@ -1080,7 +1081,7 @@ const NestedPrint = union(enum) {...@@ -1080,7 +1081,7 @@ const NestedPrint = union(enum) {
1080 },1081 },
1081};1082};
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 {
1084 try w.writeByte('&');1085 try w.writeByte('&');
1085 try w.writeAll(base);1086 try w.writeAll(base);
1086 if (!offset.isZero(comp)) {1087 if (!offset.isZero(comp)) {
...@@ -1089,7 +1090,7 @@ pub fn printPointer(offset: Value, base: []const u8, comp: *const Compilation, w...@@ -1089,7 +1090,7 @@ pub fn printPointer(offset: Value, base: []const u8, comp: *const Compilation, w
1089 }1090 }
1090}1091}
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 {
1093 if (qt.is(comp, .bool)) {1094 if (qt.is(comp, .bool)) {
1094 try w.writeAll(if (v.isZero(comp)) "false" else "true");1095 try w.writeAll(if (v.isZero(comp)) "false" else "true");
1095 return null;1096 return null;
...@@ -1116,7 +1117,7 @@ pub fn print(v: Value, qt: QualType, comp: *const Compilation, w: *std.Io.Writer...@@ -1116,7 +1117,7 @@ pub fn print(v: Value, qt: QualType, comp: *const Compilation, w: *std.Io.Writer
1116 return null;1117 return null;
1117}1118}
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 {
1120 const size: Compilation.CharUnitSize = @enumFromInt(qt.childType(comp).sizeof(comp));1121 const size: Compilation.CharUnitSize = @enumFromInt(qt.childType(comp).sizeof(comp));
1121 const without_null = bytes[0 .. bytes.len - @intFromEnum(size)];1122 const without_null = bytes[0 .. bytes.len - @intFromEnum(size)];
1122 try w.writeByte('"');1123 try w.writeByte('"');
lib/compiler/aro/main.zig+1-1
...@@ -59,7 +59,7 @@ pub fn main() u8 {...@@ -59,7 +59,7 @@ pub fn main() u8 {
59 } },59 } },
60 };60 };
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) {
63 error.OutOfMemory => {63 error.OutOfMemory => {
64 std.debug.print("out of memory\n", .{});64 std.debug.print("out of memory\n", .{});
65 if (fast_exit) process.exit(1);65 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...@@ -152,7 +152,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
152 defer threaded.deinit();152 defer threaded.deinit();
153 const io = threaded.io();153 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 });
156 defer input_file.close(io);156 defer input_file.close(io);
157157
158 const stat = input_file.stat() catch |err| fatal("failed to stat {s}: {t}", .{ input, err });158 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...@@ -180,7 +180,7 @@ fn cmdObjCopy(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
180180
181 const mode = if (out_fmt != .elf or only_keep_debug) Io.File.default_mode else stat.mode;181 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 });
184 defer output_file.close(io);184 defer output_file.close(io);
185185
186 var out = output_file.writer(&output_buffer);186 var out = output_file.writer(&output_buffer);
lib/compiler/reduce.zig+3-3
...@@ -233,7 +233,7 @@ pub fn main() !void {...@@ -233,7 +233,7 @@ pub fn main() !void {
233 }233 }
234 }234 }
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() });
237 // std.debug.print("trying this code:\n{s}\n", .{rendered.items});237 // std.debug.print("trying this code:\n{s}\n", .{rendered.items});
238238
239 const interestingness = try runCheck(arena, interestingness_argv.items);239 const interestingness = try runCheck(arena, interestingness_argv.items);
...@@ -274,7 +274,7 @@ pub fn main() !void {...@@ -274,7 +274,7 @@ pub fn main() !void {
274 fixups.clearRetainingCapacity();274 fixups.clearRetainingCapacity();
275 rendered.clearRetainingCapacity();275 rendered.clearRetainingCapacity();
276 try tree.render(gpa, &rendered.writer, fixups);276 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
279 return std.process.cleanExit();279 return std.process.cleanExit();
280 }280 }
...@@ -398,7 +398,7 @@ fn transformationsToFixups(...@@ -398,7 +398,7 @@ fn transformationsToFixups(
398}398}
399399
400fn parse(gpa: Allocator, file_path: []const u8) !Ast {400fn parse(gpa: Allocator, file_path: []const u8) !Ast {
401 const source_code = std.fs.cwd().readFileAllocOptions(401 const source_code = Io.Dir.cwd().readFileAllocOptions(
402 file_path,402 file_path,
403 gpa,403 gpa,
404 .limited(std.math.maxInt(u32)),404 .limited(std.math.maxInt(u32)),
lib/compiler/resinator/cli.zig+1-1
...@@ -2003,7 +2003,7 @@ test "maybeAppendRC" {...@@ -2003,7 +2003,7 @@ test "maybeAppendRC" {
20032003
2004 // Create the file so that it's found. In this scenario, .rc should not get2004 // Create the file so that it's found. In this scenario, .rc should not get
2005 // appended.2005 // appended.
2006 var file = try tmp.dir.createFile("foo", .{});2006 var file = try tmp.dir.createFile(io, "foo", .{});
2007 file.close(io);2007 file.close(io);
2008 try options.maybeAppendRC(tmp.dir);2008 try options.maybeAppendRC(tmp.dir);
2009 try std.testing.expectEqualStrings("foo", options.input_source.filename);2009 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...@@ -111,7 +111,7 @@ pub fn compile(allocator: Allocator, io: Io, source: []const u8, writer: *std.Io
111 try search_dirs.append(allocator, .{ .dir = root_dir, .path = try allocator.dupe(u8, root_dir_path) });111 try search_dirs.append(allocator, .{ .dir = root_dir, .path = try allocator.dupe(u8, root_dir_path) });
112 }112 }
113 }113 }
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)
115 const cwd_dir = options.cwd.openDir(".", .{}) catch |err| {115 const cwd_dir = options.cwd.openDir(".", .{}) catch |err| {
116 try options.diagnostics.append(.{116 try options.diagnostics.append(.{
117 .err = .failed_to_open_cwd,117 .err = .failed_to_open_cwd,
...@@ -406,7 +406,7 @@ pub const Compiler = struct {...@@ -406,7 +406,7 @@ pub const Compiler = struct {
406 // `/test.bin` relative to include paths and instead only treats it as406 // `/test.bin` relative to include paths and instead only treats it as
407 // an absolute path.407 // an absolute path.
408 if (std.fs.path.isAbsolute(path)) {408 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, .{});
410 errdefer file.close(io);410 errdefer file.close(io);
411411
412 if (self.dependencies) |dependencies| {412 if (self.dependencies) |dependencies| {
lib/compiler/resinator/main.zig+11-11
...@@ -67,7 +67,7 @@ pub fn main() !void {...@@ -67,7 +67,7 @@ pub fn main() !void {
67 },67 },
68 else => |e| return e,68 else => |e| return e,
69 };69 };
70 try options.maybeAppendRC(std.fs.cwd());70 try options.maybeAppendRC(Io.Dir.cwd());
7171
72 if (!zig_integration) {72 if (!zig_integration) {
73 // print any warnings/notes73 // print any warnings/notes
...@@ -141,7 +141,7 @@ pub fn main() !void {...@@ -141,7 +141,7 @@ pub fn main() !void {
141 if (!zig_integration) std.debug.unlockStderrWriter();141 if (!zig_integration) std.debug.unlockStderrWriter();
142 }142 }
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());
145 defer comp.deinit();145 defer comp.deinit();
146146
147 var argv: std.ArrayList([]const u8) = .empty;147 var argv: std.ArrayList([]const u8) = .empty;
...@@ -196,7 +196,7 @@ pub fn main() !void {...@@ -196,7 +196,7 @@ pub fn main() !void {
196 };196 };
197 },197 },
198 .filename => |input_filename| {198 .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| {
200 try error_handler.emitMessage(gpa, .err, "unable to read input file path '{s}': {s}", .{ input_filename, @errorName(err) });200 try error_handler.emitMessage(gpa, .err, "unable to read input file path '{s}': {s}", .{ input_filename, @errorName(err) });
201 std.process.exit(1);201 std.process.exit(1);
202 };202 };
...@@ -212,7 +212,7 @@ pub fn main() !void {...@@ -212,7 +212,7 @@ pub fn main() !void {
212 try output_file.writeAll(full_input);212 try output_file.writeAll(full_input);
213 },213 },
214 .filename => |output_filename| {214 .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 });
216 },216 },
217 }217 }
218 return;218 return;
...@@ -277,7 +277,7 @@ pub fn main() !void {...@@ -277,7 +277,7 @@ pub fn main() !void {
277 const output_buffered_stream = res_stream_writer.interface();277 const output_buffered_stream = res_stream_writer.interface();
278278
279 compile(gpa, io, final_input, output_buffered_stream, .{279 compile(gpa, io, final_input, output_buffered_stream, .{
280 .cwd = std.fs.cwd(),280 .cwd = Io.Dir.cwd(),
281 .diagnostics = &diagnostics,281 .diagnostics = &diagnostics,
282 .source_mappings = &mapping_results.mappings,282 .source_mappings = &mapping_results.mappings,
283 .dependencies = maybe_dependencies,283 .dependencies = maybe_dependencies,
...@@ -294,7 +294,7 @@ pub fn main() !void {...@@ -294,7 +294,7 @@ pub fn main() !void {
294 .warn_instead_of_error_on_invalid_code_page = options.warn_instead_of_error_on_invalid_code_page,294 .warn_instead_of_error_on_invalid_code_page = options.warn_instead_of_error_on_invalid_code_page,
295 }) catch |err| switch (err) {295 }) catch |err| switch (err) {
296 error.ParseError, error.CompileError => {296 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);
298 // Delete the output file on error298 // Delete the output file on error
299 res_stream.cleanupAfterError(io);299 res_stream.cleanupAfterError(io);
300 std.process.exit(1);300 std.process.exit(1);
...@@ -306,12 +306,12 @@ pub fn main() !void {...@@ -306,12 +306,12 @@ pub fn main() !void {
306306
307 // print any warnings/notes307 // print any warnings/notes
308 if (!zig_integration) {308 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);
310 }310 }
311311
312 // write the depfile312 // write the depfile
313 if (options.depfile_path) |depfile_path| {313 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| {
315 try error_handler.emitMessage(gpa, .err, "unable to create depfile '{s}': {s}", .{ depfile_path, @errorName(err) });315 try error_handler.emitMessage(gpa, .err, "unable to create depfile '{s}': {s}", .{ depfile_path, @errorName(err) });
316 std.process.exit(1);316 std.process.exit(1);
317 };317 };
...@@ -440,7 +440,7 @@ const IoStream = struct {...@@ -440,7 +440,7 @@ const IoStream = struct {
440 // Delete the output file on error440 // Delete the output file on error
441 file.close(io);441 file.close(io);
442 // Failing to delete is not really a big deal, so swallow any errors442 // 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 {};
444 },444 },
445 .stdio, .memory, .closed => return,445 .stdio, .memory, .closed => return,
446 }446 }
...@@ -457,8 +457,8 @@ const IoStream = struct {...@@ -457,8 +457,8 @@ const IoStream = struct {
457 switch (source) {457 switch (source) {
458 .filename => |filename| return .{458 .filename => |filename| return .{
459 .file = switch (io) {459 .file = switch (io) {
460 .input => try openFileNotDir(std.fs.cwd(), filename, .{}),460 .input => try openFileNotDir(Io.Dir.cwd(), filename, .{}),
461 .output => try std.fs.cwd().createFile(filename, .{}),461 .output => try Io.Dir.cwd().createFile(io, filename, .{}),
462 },462 },
463 },463 },
464 .stdio => |file| return .{ .stdio = file },464 .stdio => |file| return .{ .stdio = file },
lib/compiler/std-docs.zig+1-1
...@@ -40,7 +40,7 @@ pub fn main() !void {...@@ -40,7 +40,7 @@ pub fn main() !void {
40 const zig_exe_path = argv.next().?;40 const zig_exe_path = argv.next().?;
41 const global_cache_path = argv.next().?;41 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, .{});
44 defer lib_dir.close(io);44 defer lib_dir.close(io);
4545
46 var listen_port: u16 = 0;46 var listen_port: u16 = 0;
lib/compiler/translate-c/main.zig+4-4
...@@ -47,7 +47,7 @@ pub fn main() u8 {...@@ -47,7 +47,7 @@ pub fn main() u8 {
47 };47 };
48 defer diagnostics.deinit();48 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) {
51 error.OutOfMemory => {51 error.OutOfMemory => {
52 std.debug.print("ran out of memory initializing C compilation\n", .{});52 std.debug.print("ran out of memory initializing C compilation\n", .{});
53 if (fast_exit) process.exit(1);53 if (fast_exit) process.exit(1);
...@@ -226,7 +226,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration...@@ -226,7 +226,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration
226 const dep_file_name = try d.getDepFileName(source, out_buf[0..std.fs.max_name_bytes]);226 const dep_file_name = try d.getDepFileName(source, out_buf[0..std.fs.max_name_bytes]);
227227
228 const file = if (dep_file_name) |path|228 const file = if (dep_file_name) |path|
229 d.comp.cwd.createFile(path, .{}) catch |er|229 d.comp.cwd.createFile(io, path, .{}) catch |er|
230 return d.fatal("unable to create dependency file '{s}': {s}", .{ path, aro.Driver.errorDescription(er) })230 return d.fatal("unable to create dependency file '{s}': {s}", .{ path, aro.Driver.errorDescription(er) })
231 else231 else
232 Io.File.stdout();232 Io.File.stdout();
...@@ -253,10 +253,10 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration...@@ -253,10 +253,10 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: [][:0]u8, zig_integration
253 if (d.output_name) |path| blk: {253 if (d.output_name) |path| blk: {
254 if (std.mem.eql(u8, path, "-")) break :blk;254 if (std.mem.eql(u8, path, "-")) break :blk;
255 if (std.fs.path.dirname(path)) |dirname| {255 if (std.fs.path.dirname(path)) |dirname| {
256 std.fs.cwd().makePath(dirname) catch |err|256 Io.Dir.cwd().makePath(dirname) catch |err|
257 return d.fatal("failed to create path to '{s}': {s}", .{ path, aro.Driver.errorDescription(err) });257 return d.fatal("failed to create path to '{s}': {s}", .{ path, aro.Driver.errorDescription(err) });
258 }258 }
259 out_file = std.fs.cwd().createFile(path, .{}) catch |err| {259 out_file = Io.Dir.cwd().createFile(io, path, .{}) catch |err| {
260 return d.fatal("failed to create output file '{s}': {s}", .{ path, aro.Driver.errorDescription(err) });260 return d.fatal("failed to create output file '{s}': {s}", .{ path, aro.Driver.errorDescription(err) });
261 };261 };
262 close_out_file = true;262 close_out_file = true;
lib/std/Build.zig+5-5
...@@ -1702,13 +1702,13 @@ pub fn addCheckFile(...@@ -1702,13 +1702,13 @@ pub fn addCheckFile(
1702pub fn truncateFile(b: *Build, dest_path: []const u8) (Io.Dir.MakeError || Io.Dir.StatFileError)!void {1702pub fn truncateFile(b: *Build, dest_path: []const u8) (Io.Dir.MakeError || Io.Dir.StatFileError)!void {
1703 const io = b.graph.io;1703 const io = b.graph.io;
1704 if (b.verbose) log.info("truncate {s}", .{dest_path});1704 if (b.verbose) log.info("truncate {s}", .{dest_path});
1705 const cwd = fs.cwd();1705 const cwd = Io.Dir.cwd();
1706 var src_file = cwd.createFile(dest_path, .{}) catch |err| switch (err) {1706 var src_file = cwd.createFile(io, dest_path, .{}) catch |err| switch (err) {
1707 error.FileNotFound => blk: {1707 error.FileNotFound => blk: {
1708 if (fs.path.dirname(dest_path)) |dirname| {1708 if (fs.path.dirname(dest_path)) |dirname| {
1709 try cwd.makePath(dirname);1709 try cwd.makePath(dirname);
1710 }1710 }
1711 break :blk try cwd.createFile(dest_path, .{});1711 break :blk try cwd.createFile(io, dest_path, .{});
1712 },1712 },
1713 else => |e| return e,1713 else => |e| return e,
1714 };1714 };
...@@ -1846,7 +1846,7 @@ pub fn runAllowFail(...@@ -1846,7 +1846,7 @@ pub fn runAllowFail(
1846 };1846 };
1847 errdefer b.allocator.free(stdout);1847 errdefer b.allocator.free(stdout);
18481848
1849 const term = try child.wait();1849 const term = try child.wait(io);
1850 switch (term) {1850 switch (term) {
1851 .Exited => |code| {1851 .Exited => |code| {
1852 if (code != 0) {1852 if (code != 0) {
...@@ -2193,7 +2193,7 @@ fn dependencyInner(...@@ -2193,7 +2193,7 @@ fn dependencyInner(
21932193
2194 const build_root: std.Build.Cache.Directory = .{2194 const build_root: std.Build.Cache.Directory = .{
2195 .path = build_root_string,2195 .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| {
2197 std.debug.print("unable to open '{s}': {s}\n", .{2197 std.debug.print("unable to open '{s}': {s}\n", .{
2198 build_root_string, @errorName(err),2198 build_root_string, @errorName(err),
2199 });2199 });
lib/std/Build/Cache.zig+4-4
...@@ -508,7 +508,7 @@ pub const Manifest = struct {...@@ -508,7 +508,7 @@ pub const Manifest = struct {
508 // and `want_shared_lock` is set, a shared lock might be sufficient, so we'll508 // and `want_shared_lock` is set, a shared lock might be sufficient, so we'll
509 // open with a shared lock instead.509 // open with a shared lock instead.
510 while (true) {510 while (true) {
511 if (self.cache.manifest_dir.createFile(&manifest_file_path, .{511 if (self.cache.manifest_dir.createFile(io, &manifest_file_path, .{
512 .read = true,512 .read = true,
513 .truncate = false,513 .truncate = false,
514 .lock = .exclusive,514 .lock = .exclusive,
...@@ -543,7 +543,7 @@ pub const Manifest = struct {...@@ -543,7 +543,7 @@ pub const Manifest = struct {
543 return error.CacheCheckFailed;543 return error.CacheCheckFailed;
544 }544 }
545545
546 if (self.cache.manifest_dir.createFile(&manifest_file_path, .{546 if (self.cache.manifest_dir.createFile(io, &manifest_file_path, .{
547 .read = true,547 .read = true,
548 .truncate = false,548 .truncate = false,
549 .lock = .exclusive,549 .lock = .exclusive,
...@@ -873,7 +873,7 @@ pub const Manifest = struct {...@@ -873,7 +873,7 @@ pub const Manifest = struct {
873 if (man.want_refresh_timestamp) {873 if (man.want_refresh_timestamp) {
874 man.want_refresh_timestamp = false;874 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", .{
877 .read = true,877 .read = true,
878 .truncate = true,878 .truncate = true,
879 }) catch |err| switch (err) {879 }) catch |err| switch (err) {
...@@ -1324,7 +1324,7 @@ fn hashFile(file: Io.File, bin_digest: *[Hasher.mac_length]u8) Io.File.PReadErro...@@ -1324,7 +1324,7 @@ fn hashFile(file: Io.File, bin_digest: *[Hasher.mac_length]u8) Io.File.PReadErro
1324fn testGetCurrentFileTimestamp(io: Io, dir: Io.Dir) !Io.Timestamp {1324fn testGetCurrentFileTimestamp(io: Io, dir: Io.Dir) !Io.Timestamp {
1325 const test_out_file = "test-filetimestamp.tmp";1325 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, .{
1328 .read = true,1328 .read = true,
1329 .truncate = true,1329 .truncate = true,
1330 });1330 });
lib/std/Build/Step.zig+9-8
...@@ -401,6 +401,9 @@ pub fn evalZigProcess(...@@ -401,6 +401,9 @@ pub fn evalZigProcess(
401 web_server: ?*Build.WebServer,401 web_server: ?*Build.WebServer,
402 gpa: Allocator,402 gpa: Allocator,
403) !?Path {403) !?Path {
404 const b = s.owner;
405 const io = b.graph.io;
406
404 // If an error occurs, it's happened in this command:407 // If an error occurs, it's happened in this command:
405 assert(s.result_failed_command == null);408 assert(s.result_failed_command == null);
406 s.result_failed_command = try allocPrintCmd(gpa, null, argv);409 s.result_failed_command = try allocPrintCmd(gpa, null, argv);
...@@ -411,7 +414,7 @@ pub fn evalZigProcess(...@@ -411,7 +414,7 @@ pub fn evalZigProcess(
411 const result = zigProcessUpdate(s, zp, watch, web_server, gpa) catch |err| switch (err) {414 const result = zigProcessUpdate(s, zp, watch, web_server, gpa) catch |err| switch (err) {
412 error.BrokenPipe => {415 error.BrokenPipe => {
413 // Process restart required.416 // Process restart required.
414 const term = zp.child.wait() catch |e| {417 const term = zp.child.wait(io) catch |e| {
415 return s.fail("unable to wait for {s}: {t}", .{ argv[0], e });418 return s.fail("unable to wait for {s}: {t}", .{ argv[0], e });
416 };419 };
417 _ = term;420 _ = term;
...@@ -427,7 +430,7 @@ pub fn evalZigProcess(...@@ -427,7 +430,7 @@ pub fn evalZigProcess(
427430
428 if (s.result_error_msgs.items.len > 0 and result == null) {431 if (s.result_error_msgs.items.len > 0 and result == null) {
429 // Crash detected.432 // Crash detected.
430 const term = zp.child.wait() catch |e| {433 const term = zp.child.wait(io) catch |e| {
431 return s.fail("unable to wait for {s}: {t}", .{ argv[0], e });434 return s.fail("unable to wait for {s}: {t}", .{ argv[0], e });
432 };435 };
433 s.result_peak_rss = zp.child.resource_usage_statistics.getMaxRss() orelse 0;436 s.result_peak_rss = zp.child.resource_usage_statistics.getMaxRss() orelse 0;
...@@ -439,9 +442,7 @@ pub fn evalZigProcess(...@@ -439,9 +442,7 @@ pub fn evalZigProcess(
439 return result;442 return result;
440 }443 }
441 assert(argv.len != 0);444 assert(argv.len != 0);
442 const b = s.owner;
443 const arena = b.allocator;445 const arena = b.allocator;
444 const io = b.graph.io;
445446
446 try handleChildProcUnsupported(s);447 try handleChildProcUnsupported(s);
447 try handleVerbose(s.owner, null, argv);448 try handleVerbose(s.owner, null, argv);
...@@ -478,7 +479,7 @@ pub fn evalZigProcess(...@@ -478,7 +479,7 @@ pub fn evalZigProcess(
478 zp.child.stdin.?.close(io);479 zp.child.stdin.?.close(io);
479 zp.child.stdin = null;480 zp.child.stdin = null;
480481
481 const term = zp.child.wait() catch |err| {482 const term = zp.child.wait(io) catch |err| {
482 return s.fail("unable to wait for {s}: {t}", .{ argv[0], err });483 return s.fail("unable to wait for {s}: {t}", .{ argv[0], err });
483 };484 };
484 s.result_peak_rss = zp.child.resource_usage_statistics.getMaxRss() orelse 0;485 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...@@ -519,7 +520,7 @@ pub fn installFile(s: *Step, src_lazy_path: Build.LazyPath, dest_path: []const u
519pub fn installDir(s: *Step, dest_path: []const u8) !Io.Dir.MakePathStatus {520pub fn installDir(s: *Step, dest_path: []const u8) !Io.Dir.MakePathStatus {
520 const b = s.owner;521 const b = s.owner;
521 try handleVerbose(b, null, &.{ "install", "-d", dest_path });522 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|
523 return s.fail("unable to create dir '{s}': {t}", .{ dest_path, err });524 return s.fail("unable to create dir '{s}': {t}", .{ dest_path, err });
524}525}
525526
...@@ -895,7 +896,7 @@ pub fn addWatchInput(step: *Step, lazy_file: Build.LazyPath) Allocator.Error!voi...@@ -895,7 +896,7 @@ pub fn addWatchInput(step: *Step, lazy_file: Build.LazyPath) Allocator.Error!voi
895 try addWatchInputFromPath(step, .{896 try addWatchInputFromPath(step, .{
896 .root_dir = .{897 .root_dir = .{
897 .path = null,898 .path = null,
898 .handle = std.fs.cwd(),899 .handle = Io.Dir.cwd(),
899 },900 },
900 .sub_path = std.fs.path.dirname(path_string) orelse "",901 .sub_path = std.fs.path.dirname(path_string) orelse "",
901 }, std.fs.path.basename(path_string));902 }, std.fs.path.basename(path_string));
...@@ -920,7 +921,7 @@ pub fn addDirectoryWatchInput(step: *Step, lazy_directory: Build.LazyPath) Alloc...@@ -920,7 +921,7 @@ pub fn addDirectoryWatchInput(step: *Step, lazy_directory: Build.LazyPath) Alloc
920 try addDirectoryWatchInputFromPath(step, .{921 try addDirectoryWatchInputFromPath(step, .{
921 .root_dir = .{922 .root_dir = .{
922 .path = null,923 .path = null,
923 .handle = std.fs.cwd(),924 .handle = Io.Dir.cwd(),
924 },925 },
925 .sub_path = path_string,926 .sub_path = path_string,
926 });927 });
lib/std/Build/Step/CheckFile.zig+3-1
...@@ -3,7 +3,9 @@...@@ -3,7 +3,9 @@
3//! TODO: generalize the code in std.testing.expectEqualStrings and make this3//! TODO: generalize the code in std.testing.expectEqualStrings and make this
4//! CheckFile step produce those helpful diagnostics when there is not a match.4//! CheckFile step produce those helpful diagnostics when there is not a match.
5const CheckFile = @This();5const CheckFile = @This();
6
6const std = @import("std");7const std = @import("std");
8const Io = std.Io;
7const Step = std.Build.Step;9const Step = std.Build.Step;
8const fs = std.fs;10const fs = std.fs;
9const mem = std.mem;11const mem = std.mem;
...@@ -53,7 +55,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {...@@ -53,7 +55,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
53 try step.singleUnchangingWatchInput(check_file.source);55 try step.singleUnchangingWatchInput(check_file.source);
5456
55 const src_path = check_file.source.getPath2(b, step);57 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| {
57 return step.fail("unable to read '{s}': {s}", .{59 return step.fail("unable to read '{s}': {s}", .{
58 src_path, @errorName(err),60 src_path, @errorName(err),
59 });61 });
lib/std/Build/Step/ConfigHeader.zig+5-3
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1const std = @import("std");
2const ConfigHeader = @This();1const ConfigHeader = @This();
2
3const std = @import("std");
4const Io = std.Io;
3const Step = std.Build.Step;5const Step = std.Build.Step;
4const Allocator = std.mem.Allocator;6const Allocator = std.mem.Allocator;
5const Writer = std.Io.Writer;7const Writer = std.Io.Writer;
...@@ -205,7 +207,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {...@@ -205,7 +207,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
205 .autoconf_undef, .autoconf_at => |file_source| {207 .autoconf_undef, .autoconf_at => |file_source| {
206 try bw.writeAll(c_generated_line);208 try bw.writeAll(c_generated_line);
207 const src_path = file_source.getPath2(b, step);209 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| {
209 return step.fail("unable to read autoconf input file '{s}': {s}", .{211 return step.fail("unable to read autoconf input file '{s}': {s}", .{
210 src_path, @errorName(err),212 src_path, @errorName(err),
211 });213 });
...@@ -219,7 +221,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {...@@ -219,7 +221,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
219 .cmake => |file_source| {221 .cmake => |file_source| {
220 try bw.writeAll(c_generated_line);222 try bw.writeAll(c_generated_line);
221 const src_path = file_source.getPath2(b, step);223 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| {
223 return step.fail("unable to read cmake input file '{s}': {s}", .{225 return step.fail("unable to read cmake input file '{s}': {s}", .{
224 src_path, @errorName(err),226 src_path, @errorName(err),
225 });227 });
lib/std/Build/Step/Options.zig+8-7
...@@ -1,12 +1,13 @@...@@ -1,12 +1,13 @@
1const std = @import("std");1const Options = @This();
2const builtin = @import("builtin");2const builtin = @import("builtin");
3
4const std = @import("std");
5const Io = std.Io;
3const fs = std.fs;6const fs = std.fs;
4const Step = std.Build.Step;7const Step = std.Build.Step;
5const GeneratedFile = std.Build.GeneratedFile;8const GeneratedFile = std.Build.GeneratedFile;
6const LazyPath = std.Build.LazyPath;9const LazyPath = std.Build.LazyPath;
710
8const Options = @This();
9
10pub const base_id: Step.Id = .options;11pub const base_id: Step.Id = .options;
1112
12step: Step,13step: Step,
...@@ -542,11 +543,11 @@ test Options {...@@ -542,11 +543,11 @@ test Options {
542 .cache = .{543 .cache = .{
543 .io = io,544 .io = io,
544 .gpa = arena.allocator(),545 .gpa = arena.allocator(),
545 .manifest_dir = std.fs.cwd(),546 .manifest_dir = Io.Dir.cwd(),
546 },547 },
547 .zig_exe = "test",548 .zig_exe = "test",
548 .env_map = std.process.EnvMap.init(arena.allocator()),549 .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() },
550 .host = .{551 .host = .{
551 .query = .{},552 .query = .{},
552 .result = try std.zig.system.resolveTargetQuery(io, .{}),553 .result = try std.zig.system.resolveTargetQuery(io, .{}),
...@@ -557,8 +558,8 @@ test Options {...@@ -557,8 +558,8 @@ test Options {
557558
558 var builder = try std.Build.create(559 var builder = try std.Build.create(
559 &graph,560 &graph,
560 .{ .path = "test", .handle = std.fs.cwd() },561 .{ .path = "test", .handle = Io.Dir.cwd() },
561 .{ .path = "test", .handle = std.fs.cwd() },562 .{ .path = "test", .handle = Io.Dir.cwd() },
562 &.{},563 &.{},
563 );564 );
564565
lib/std/Build/Step/Run.zig+1-1
...@@ -1023,7 +1023,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {...@@ -1023,7 +1023,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
10231023
1024 try runCommand(run, argv_list.items, has_side_effects, tmp_dir_path, options, null);1024 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();
1027 const dep_file_basename = dep_output_file.generated_file.getPath2(b, step);1027 const dep_file_basename = dep_output_file.generated_file.getPath2(b, step);
1028 if (has_side_effects)1028 if (has_side_effects)
1029 try man.addDepFile(dep_file_dir, dep_file_basename)1029 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) {...@@ -122,7 +122,7 @@ const Os = switch (builtin.os.tag) {
122 }) catch return error.NameTooLong;122 }) catch return error.NameTooLong;
123 const stack_ptr: *std.os.linux.file_handle = @ptrCast(&file_handle_buffer);123 const stack_ptr: *std.os.linux.file_handle = @ptrCast(&file_handle_buffer);
124 stack_ptr.handle_bytes = file_handle_buffer.len - @sizeOf(std.os.linux.file_handle);124 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);
126 const stack_lfh: FileHandle = .{ .handle = stack_ptr };126 const stack_lfh: FileHandle = .{ .handle = stack_ptr };
127 return stack_lfh.clone(gpa);127 return stack_lfh.clone(gpa);
128 }128 }
...@@ -222,7 +222,7 @@ const Os = switch (builtin.os.tag) {...@@ -222,7 +222,7 @@ const Os = switch (builtin.os.tag) {
222 posix.fanotify_mark(fan_fd, .{222 posix.fanotify_mark(fan_fd, .{
223 .ADD = true,223 .ADD = true,
224 .ONLYDIR = true,224 .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| {
226 fatal("unable to watch {f}: {s}", .{ path, @errorName(err) });226 fatal("unable to watch {f}: {s}", .{ path, @errorName(err) });
227 };227 };
228 }228 }
...@@ -275,7 +275,7 @@ const Os = switch (builtin.os.tag) {...@@ -275,7 +275,7 @@ const Os = switch (builtin.os.tag) {
275 posix.fanotify_mark(fan_fd, .{275 posix.fanotify_mark(fan_fd, .{
276 .REMOVE = true,276 .REMOVE = true,
277 .ONLYDIR = true,277 .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) {
279 error.FileNotFound => {}, // Expected, harmless.279 error.FileNotFound => {}, // Expected, harmless.
280 else => |e| std.log.warn("unable to unwatch '{f}': {s}", .{ path, @errorName(e) }),280 else => |e| std.log.warn("unable to unwatch '{f}': {s}", .{ path, @errorName(e) }),
281 };281 };
...@@ -353,7 +353,7 @@ const Os = switch (builtin.os.tag) {...@@ -353,7 +353,7 @@ const Os = switch (builtin.os.tag) {
353 // The following code is a drawn out NtCreateFile call. (mostly adapted from Io.Dir.makeOpenDirAccessMaskW)353 // The following code is a drawn out NtCreateFile call. (mostly adapted from Io.Dir.makeOpenDirAccessMaskW)
354 // It's necessary in order to get the specific flags that are required when calling ReadDirectoryChangesW.354 // It's necessary in order to get the specific flags that are required when calling ReadDirectoryChangesW.
355 var dir_handle: windows.HANDLE = undefined;355 var dir_handle: windows.HANDLE = undefined;
356 const root_fd = path.root_dir.handle.fd;356 const root_fd = path.root_dir.handle.handle;
357 const sub_path = path.subPathOrDot();357 const sub_path = path.subPathOrDot();
358 const sub_path_w = try windows.sliceToPrefixedFileW(root_fd, sub_path);358 const sub_path_w = try windows.sliceToPrefixedFileW(root_fd, sub_path);
359 const path_len_bytes = std.math.cast(u16, sub_path_w.len * 2) orelse return error.NameTooLong;359 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) {...@@ -681,9 +681,9 @@ const Os = switch (builtin.os.tag) {
681 if (!gop.found_existing) {681 if (!gop.found_existing) {
682 const skip_open_dir = path.sub_path.len == 0;682 const skip_open_dir = path.sub_path.len == 0;
683 const dir_fd = if (skip_open_dir)683 const dir_fd = if (skip_open_dir)
684 path.root_dir.handle.fd684 path.root_dir.handle.handle
685 else685 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| {
687 fatal("failed to open directory {f}: {s}", .{ path, @errorName(err) });687 fatal("failed to open directory {f}: {s}", .{ path, @errorName(err) });
688 };688 };
689 // Empirically the dir has to stay open or else no events are triggered.689 // Empirically the dir has to stay open or else no events are triggered.
...@@ -750,7 +750,7 @@ const Os = switch (builtin.os.tag) {...@@ -750,7 +750,7 @@ const Os = switch (builtin.os.tag) {
750 // to access that data via the dir_fd field.750 // to access that data via the dir_fd field.
751 const path = w.dir_table.keys()[i];751 const path = w.dir_table.keys()[i];
752 const dir_fd = if (path.sub_path.len == 0)752 const dir_fd = if (path.sub_path.len == 0)
753 path.root_dir.handle.fd753 path.root_dir.handle.handle
754 else754 else
755 handles.items(.dir_fd)[i];755 handles.items(.dir_fd)[i];
756 assert(dir_fd != -1);756 assert(dir_fd != -1);
...@@ -761,7 +761,7 @@ const Os = switch (builtin.os.tag) {...@@ -761,7 +761,7 @@ const Os = switch (builtin.os.tag) {
761 const last_dir_fd = fd: {761 const last_dir_fd = fd: {
762 const last_path = w.dir_table.keys()[handles.len - 1];762 const last_path = w.dir_table.keys()[handles.len - 1];
763 const last_dir_fd = if (last_path.sub_path.len == 0)763 const last_dir_fd = if (last_path.sub_path.len == 0)
764 last_path.root_dir.handle.fd764 last_path.root_dir.handle.handle
765 else765 else
766 handles.items(.dir_fd)[handles.len - 1];766 handles.items(.dir_fd)[handles.len - 1];
767 assert(last_dir_fd != -1);767 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 {...@@ -527,6 +527,14 @@ pub fn writerStreaming(file: File, io: Io, buffer: []u8) Writer {
527 return .initStreaming(file, io, buffer);527 return .initStreaming(file, io, buffer);
528}528}
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
530pub const LockError = error{538pub const LockError = error{
531 SystemResources,539 SystemResources,
532 FileLocksUnsupported,540 FileLocksUnsupported,
lib/std/Io/Threaded.zig+3-6
...@@ -2361,7 +2361,7 @@ fn dirCreateFilePosix(...@@ -2361,7 +2361,7 @@ fn dirCreateFilePosix(
2361 .NFILE => return error.SystemFdQuotaExceeded,2361 .NFILE => return error.SystemFdQuotaExceeded,
2362 .NODEV => return error.NoDevice,2362 .NODEV => return error.NoDevice,
2363 .NOENT => return error.FileNotFound,2363 .NOENT => return error.FileNotFound,
2364 .SRCH => return error.ProcessNotFound,2364 .SRCH => return error.FileNotFound, // Linux when accessing procfs.
2365 .NOMEM => return error.SystemResources,2365 .NOMEM => return error.SystemResources,
2366 .NOSPC => return error.NoSpaceLeft,2366 .NOSPC => return error.NoSpaceLeft,
2367 .NOTDIR => return error.NotDir,2367 .NOTDIR => return error.NotDir,
...@@ -2670,7 +2670,7 @@ fn dirOpenFilePosix(...@@ -2670,7 +2670,7 @@ fn dirOpenFilePosix(
2670 .NFILE => return error.SystemFdQuotaExceeded,2670 .NFILE => return error.SystemFdQuotaExceeded,
2671 .NODEV => return error.NoDevice,2671 .NODEV => return error.NoDevice,
2672 .NOENT => return error.FileNotFound,2672 .NOENT => return error.FileNotFound,
2673 .SRCH => return error.ProcessNotFound,2673 .SRCH => return error.FileNotFound, // Linux when opening procfs files.
2674 .NOMEM => return error.SystemResources,2674 .NOMEM => return error.SystemResources,
2675 .NOSPC => return error.NoSpaceLeft,2675 .NOSPC => return error.NoSpaceLeft,
2676 .NOTDIR => return error.NotDir,2676 .NOTDIR => return error.NotDir,
...@@ -3287,7 +3287,7 @@ fn dirRealPathPosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, out_b...@@ -3287,7 +3287,7 @@ fn dirRealPathPosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, out_b
3287 .NFILE => return error.SystemFdQuotaExceeded,3287 .NFILE => return error.SystemFdQuotaExceeded,
3288 .NODEV => return error.NoDevice,3288 .NODEV => return error.NoDevice,
3289 .NOENT => return error.FileNotFound,3289 .NOENT => return error.FileNotFound,
3290 .SRCH => return error.ProcessNotFound,3290 .SRCH => return error.FileNotFound, // Linux when accessing procfs.
3291 .NOMEM => return error.SystemResources,3291 .NOMEM => return error.SystemResources,
3292 .NOSPC => return error.NoSpaceLeft,3292 .NOSPC => return error.NoSpaceLeft,
3293 .NOTDIR => return error.NotDir,3293 .NOTDIR => return error.NotDir,
...@@ -5548,7 +5548,6 @@ fn fileReadStreamingPosix(userdata: ?*anyopaque, file: File, data: [][]u8) File....@@ -5548,7 +5548,6 @@ fn fileReadStreamingPosix(userdata: ?*anyopaque, file: File, data: [][]u8) File.
5548 switch (e) {5548 switch (e) {
5549 .INVAL => |err| return errnoBug(err),5549 .INVAL => |err| return errnoBug(err),
5550 .FAULT => |err| return errnoBug(err),5550 .FAULT => |err| return errnoBug(err),
5551 .SRCH => return error.ProcessNotFound,
5552 .AGAIN => return error.WouldBlock,5551 .AGAIN => return error.WouldBlock,
5553 .BADF => |err| {5552 .BADF => |err| {
5554 if (native_os == .wasi) return error.NotOpenForReading; // File operation on directory.5553 if (native_os == .wasi) return error.NotOpenForReading; // File operation on directory.
...@@ -5672,7 +5671,6 @@ fn fileReadPositionalPosix(userdata: ?*anyopaque, file: File, data: [][]u8, offs...@@ -5672,7 +5671,6 @@ fn fileReadPositionalPosix(userdata: ?*anyopaque, file: File, data: [][]u8, offs
5672 switch (e) {5671 switch (e) {
5673 .INVAL => |err| return errnoBug(err),5672 .INVAL => |err| return errnoBug(err),
5674 .FAULT => |err| return errnoBug(err),5673 .FAULT => |err| return errnoBug(err),
5675 .SRCH => return error.ProcessNotFound,
5676 .AGAIN => return error.WouldBlock,5674 .AGAIN => return error.WouldBlock,
5677 .BADF => |err| {5675 .BADF => |err| {
5678 if (native_os == .wasi) return error.NotOpenForReading; // File operation on directory.5676 if (native_os == .wasi) return error.NotOpenForReading; // File operation on directory.
...@@ -6312,7 +6310,6 @@ fn fileWriteStreaming(...@@ -6312,7 +6310,6 @@ fn fileWriteStreaming(
6312 switch (e) {6310 switch (e) {
6313 .INVAL => return error.InvalidArgument,6311 .INVAL => return error.InvalidArgument,
6314 .FAULT => |err| return errnoBug(err),6312 .FAULT => |err| return errnoBug(err),
6315 .SRCH => return error.ProcessNotFound,
6316 .AGAIN => return error.WouldBlock,6313 .AGAIN => return error.WouldBlock,
6317 .BADF => return error.NotOpenForWriting, // Can be a race condition.6314 .BADF => return error.NotOpenForWriting, // Can be a race condition.
6318 .DESTADDRREQ => |err| return errnoBug(err), // `connect` was never called.6315 .DESTADDRREQ => |err| return errnoBug(err), // `connect` was never called.
lib/std/Io/Writer.zig+3-3
...@@ -2835,7 +2835,7 @@ test "discarding sendFile" {...@@ -2835,7 +2835,7 @@ test "discarding sendFile" {
2835 var tmp_dir = testing.tmpDir(.{});2835 var tmp_dir = testing.tmpDir(.{});
2836 defer tmp_dir.cleanup();2836 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 });
2839 defer file.close(io);2839 defer file.close(io);
2840 var r_buffer: [256]u8 = undefined;2840 var r_buffer: [256]u8 = undefined;
2841 var file_writer: File.Writer = .init(file, &r_buffer);2841 var file_writer: File.Writer = .init(file, &r_buffer);
...@@ -2857,7 +2857,7 @@ test "allocating sendFile" {...@@ -2857,7 +2857,7 @@ test "allocating sendFile" {
2857 var tmp_dir = testing.tmpDir(.{});2857 var tmp_dir = testing.tmpDir(.{});
2858 defer tmp_dir.cleanup();2858 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 });
2861 defer file.close(io);2861 defer file.close(io);
2862 var r_buffer: [2]u8 = undefined;2862 var r_buffer: [2]u8 = undefined;
2863 var file_writer: File.Writer = .init(file, &r_buffer);2863 var file_writer: File.Writer = .init(file, &r_buffer);
...@@ -2881,7 +2881,7 @@ test sendFileReading {...@@ -2881,7 +2881,7 @@ test sendFileReading {
2881 var tmp_dir = testing.tmpDir(.{});2881 var tmp_dir = testing.tmpDir(.{});
2882 defer tmp_dir.cleanup();2882 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 });
2885 defer file.close(io);2885 defer file.close(io);
2886 var r_buffer: [2]u8 = undefined;2886 var r_buffer: [2]u8 = undefined;
2887 var file_writer: File.Writer = .init(file, &r_buffer);2887 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" {...@@ -278,7 +278,7 @@ test "listen on a unix socket, send bytes, receive bytes" {
278 defer testing.allocator.free(socket_path);278 defer testing.allocator.free(socket_path);
279279
280 const socket_addr = try net.UnixAddress.init(socket_path);280 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
283 var server = try socket_addr.listen(io, .{});283 var server = try socket_addr.listen(io, .{});
284 defer server.socket.close(io);284 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" {...@@ -27,7 +27,7 @@ test "write a file, read it, then delete it" {
27 random.bytes(data[0..]);27 random.bytes(data[0..]);
28 const tmp_file_name = "temp_test_file.txt";28 const tmp_file_name = "temp_test_file.txt";
29 {29 {
30 var file = try tmp.dir.createFile(tmp_file_name, .{});30 var file = try tmp.dir.createFile(io, tmp_file_name, .{});
31 defer file.close(io);31 defer file.close(io);
3232
33 var file_writer = file.writer(&.{});33 var file_writer = file.writer(&.{});
...@@ -40,7 +40,7 @@ test "write a file, read it, then delete it" {...@@ -40,7 +40,7 @@ test "write a file, read it, then delete it" {
4040
41 {41 {
42 // Make sure the exclusive flag is honored.42 // 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 }));
44 }44 }
4545
46 {46 {
...@@ -70,7 +70,7 @@ test "File seek ops" {...@@ -70,7 +70,7 @@ test "File seek ops" {
70 const io = testing.io;70 const io = testing.io;
7171
72 const tmp_file_name = "temp_test_file.txt";72 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, .{});
74 defer file.close(io);74 defer file.close(io);
7575
76 try file.writeAll(&([_]u8{0x55} ** 8192));76 try file.writeAll(&([_]u8{0x55} ** 8192));
...@@ -96,7 +96,7 @@ test "setEndPos" {...@@ -96,7 +96,7 @@ test "setEndPos" {
96 defer tmp.cleanup();96 defer tmp.cleanup();
9797
98 const tmp_file_name = "temp_test_file.txt";98 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, .{});
100 defer file.close(io);100 defer file.close(io);
101101
102 // Verify that the file size changes and the file offset is not moved102 // Verify that the file size changes and the file offset is not moved
...@@ -121,7 +121,7 @@ test "updateTimes" {...@@ -121,7 +121,7 @@ test "updateTimes" {
121 defer tmp.cleanup();121 defer tmp.cleanup();
122122
123 const tmp_file_name = "just_a_temporary_file.txt";123 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 });
125 defer file.close(io);125 defer file.close(io);
126126
127 const stat_old = try file.stat();127 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 {...@@ -208,7 +208,7 @@ pub fn setName(self: Thread, io: Io, name: []const u8) SetNameError!void {
208 var buf: [32]u8 = undefined;208 var buf: [32]u8 = undefined;
209 const path = try std.fmt.bufPrint(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()});209 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 });
212 defer file.close(io);212 defer file.close(io);
213213
214 try file.writeAll(name);214 try file.writeAll(name);
...@@ -325,7 +325,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co...@@ -325,7 +325,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
325 var threaded: std.Io.Threaded = .init_single_threaded;325 var threaded: std.Io.Threaded = .init_single_threaded;
326 const io = threaded.ioBasic();326 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, .{});
329 defer file.close(io);329 defer file.close(io);
330330
331 var file_reader = file.readerStreaming(io, &.{});331 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...@@ -19,7 +19,7 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanM
1919
20 _ = io; // TODO migrate file system to use std.Io20 _ = io; // TODO migrate file system to use std.Io
21 for (keychain_paths) |keychain_path| {21 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) {
23 error.StreamTooLong => return error.FileTooBig,23 error.StreamTooLong => return error.FileTooBig,
24 else => |e| return e,24 else => |e| return e,
25 };25 };
lib/std/crypto/codecs/asn1/test.zig+2-2
...@@ -73,8 +73,8 @@ test AllTypes {...@@ -73,8 +73,8 @@ test AllTypes {
73 try std.testing.expectEqualSlices(u8, encoded, buf);73 try std.testing.expectEqualSlices(u8, encoded, buf);
7474
75 // Use this to update test file.75 // Use this to update test file.
76 // const dir = try std.fs.cwd().openDir("lib/std/crypto/asn1", .{});76 // const dir = try Io.Dir.cwd().openDir("lib/std/crypto/asn1", .{});
77 // var file = try dir.createFile(path, .{});77 // var file = try dir.createFile(io, path, .{});
78 // defer file.close(io);78 // defer file.close(io);
79 // try file.writeAll(buf);79 // try file.writeAll(buf);
80}80}
lib/std/debug.zig+10-10
...@@ -60,7 +60,7 @@ pub const cpu_context = @import("debug/cpu_context.zig");...@@ -60,7 +60,7 @@ pub const cpu_context = @import("debug/cpu_context.zig");
60/// };60/// };
61/// /// Only required if `can_unwind == true`. Unwinds a single stack frame, returning the frame's61/// /// Only required if `can_unwind == true`. Unwinds a single stack frame, returning the frame's
62/// /// return address, or 0 if the end of the stack has been reached.62/// /// 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;
64/// ```64/// ```
65pub const SelfInfo = if (@hasDecl(root, "debug") and @hasDecl(root.debug, "SelfInfo"))65pub const SelfInfo = if (@hasDecl(root, "debug") and @hasDecl(root.debug, "SelfInfo"))
66 root.debug.SelfInfo66 root.debug.SelfInfo
...@@ -558,9 +558,9 @@ pub fn defaultPanic(...@@ -558,9 +558,9 @@ pub fn defaultPanic(
558 stderr.print("{s}\n", .{msg}) catch break :trace;558 stderr.print("{s}\n", .{msg}) catch break :trace;
559559
560 if (@errorReturnTrace()) |t| if (t.index > 0) {560 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;
562 writeStackTrace(t, stderr, tty_config) catch break :trace;562 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;
564 };564 };
565 writeCurrentStackTrace(.{565 writeCurrentStackTrace(.{
566 .first_address = first_trace_addr orelse @returnAddress(),566 .first_address = first_trace_addr orelse @returnAddress(),
...@@ -575,7 +575,7 @@ pub fn defaultPanic(...@@ -575,7 +575,7 @@ pub fn defaultPanic(
575 // A panic happened while trying to print a previous panic message.575 // A panic happened while trying to print a previous panic message.
576 // We're still holding the mutex but that's fine as we're going to576 // We're still holding the mutex but that's fine as we're going to
577 // call abort().577 // call abort().
578 File.stderr().writeAll("aborting due to recursive panic\n") catch {};578 File.stderr().writeStreamingAll("aborting due to recursive panic\n") catch {};
579 },579 },
580 else => {}, // Panicked while printing the recursive panic message.580 else => {}, // Panicked while printing the recursive panic message.
581 }581 }
...@@ -960,7 +960,7 @@ const StackIterator = union(enum) {...@@ -960,7 +960,7 @@ const StackIterator = union(enum) {
960 },960 },
961 };961 };
962962
963 fn next(it: *StackIterator) Result {963 fn next(it: *StackIterator, io: Io) Result {
964 switch (it.*) {964 switch (it.*) {
965 .ctx_first => |context_ptr| {965 .ctx_first => |context_ptr| {
966 // After the first frame, start actually unwinding.966 // After the first frame, start actually unwinding.
...@@ -976,7 +976,7 @@ const StackIterator = union(enum) {...@@ -976,7 +976,7 @@ const StackIterator = union(enum) {
976 .di => |*unwind_context| {976 .di => |*unwind_context| {
977 const di = getSelfDebugInfo() catch unreachable;977 const di = getSelfDebugInfo() catch unreachable;
978 const di_gpa = getDebugInfoAllocator();978 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| {
980 const pc = unwind_context.pc;980 const pc = unwind_context.pc;
981 const fp = unwind_context.getFp();981 const fp = unwind_context.getFp();
982 it.* = .{ .fp = fp };982 it.* = .{ .fp = fp };
...@@ -1297,7 +1297,7 @@ test printLineFromFile {...@@ -1297,7 +1297,7 @@ test printLineFromFile {
1297 aw.clearRetainingCapacity();1297 aw.clearRetainingCapacity();
1298 }1298 }
1299 {1299 {
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", .{});
1301 defer file.close(io);1301 defer file.close(io);
1302 const path = try fs.path.join(gpa, &.{ test_dir_path, "line_overlaps_page_boundary.zig" });1302 const path = try fs.path.join(gpa, &.{ test_dir_path, "line_overlaps_page_boundary.zig" });
1303 defer gpa.free(path);1303 defer gpa.free(path);
...@@ -1316,7 +1316,7 @@ test printLineFromFile {...@@ -1316,7 +1316,7 @@ test printLineFromFile {
1316 aw.clearRetainingCapacity();1316 aw.clearRetainingCapacity();
1317 }1317 }
1318 {1318 {
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", .{});
1320 defer file.close(io);1320 defer file.close(io);
1321 const path = try fs.path.join(gpa, &.{ test_dir_path, "file_ends_on_page_boundary.zig" });1321 const path = try fs.path.join(gpa, &.{ test_dir_path, "file_ends_on_page_boundary.zig" });
1322 defer gpa.free(path);1322 defer gpa.free(path);
...@@ -1330,7 +1330,7 @@ test printLineFromFile {...@@ -1330,7 +1330,7 @@ test printLineFromFile {
1330 aw.clearRetainingCapacity();1330 aw.clearRetainingCapacity();
1331 }1331 }
1332 {1332 {
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", .{});
1334 defer file.close(io);1334 defer file.close(io);
1335 const path = try fs.path.join(gpa, &.{ test_dir_path, "very_long_first_line_spanning_multiple_pages.zig" });1335 const path = try fs.path.join(gpa, &.{ test_dir_path, "very_long_first_line_spanning_multiple_pages.zig" });
1336 defer gpa.free(path);1336 defer gpa.free(path);
...@@ -1356,7 +1356,7 @@ test printLineFromFile {...@@ -1356,7 +1356,7 @@ test printLineFromFile {
1356 aw.clearRetainingCapacity();1356 aw.clearRetainingCapacity();
1357 }1357 }
1358 {1358 {
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", .{});
1360 defer file.close(io);1360 defer file.close(io);
1361 const path = try fs.path.join(gpa, &.{ test_dir_path, "file_of_newlines.zig" });1361 const path = try fs.path.join(gpa, &.{ test_dir_path, "file_of_newlines.zig" });
1362 defer gpa.free(path);1362 defer gpa.free(path);
lib/std/debug/ElfFile.zig+1-1
...@@ -375,7 +375,7 @@ fn loadSeparateDebugFile(...@@ -375,7 +375,7 @@ fn loadSeparateDebugFile(
375 args: anytype,375 args: anytype,
376) Allocator.Error!?[]align(std.heap.page_size_min) const u8 {376) Allocator.Error!?[]align(std.heap.page_size_min) const u8 {
377 const path = try std.fmt.allocPrint(arena, fmt, args);377 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;
379 defer elf_file.close(io);379 defer elf_file.close(io);
380380
381 const result = loadInner(arena, elf_file, opt_crc) catch |err| switch (err) {381 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 {...@@ -512,7 +512,7 @@ fn loadOFile(gpa: Allocator, io: Io, o_file_name: []const u8) !OFile {
512512
513/// Uses `mmap` to map the file at `path` into memory.513/// Uses `mmap` to map the file at `path` into memory.
514fn mapDebugInfoFile(io: Io, path: []const u8) ![]align(std.heap.page_size_min) const u8 {514fn 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) {
516 error.FileNotFound => return error.MissingDebugInfo,516 error.FileNotFound => return error.MissingDebugInfo,
517 else => return error.ReadFailed,517 else => return error.ReadFailed,
518 };518 };
lib/std/debug/SelfInfo/Elf.zig+9-10
...@@ -29,13 +29,12 @@ pub fn deinit(si: *SelfInfo, gpa: Allocator) void {...@@ -29,13 +29,12 @@ pub fn deinit(si: *SelfInfo, gpa: Allocator) void {
29}29}
3030
31pub fn getSymbol(si: *SelfInfo, gpa: Allocator, io: Io, address: usize) Error!std.debug.Symbol {31pub fn getSymbol(si: *SelfInfo, gpa: Allocator, io: Io, address: usize) Error!std.debug.Symbol {
32 _ = io;
33 const module = try si.findModule(gpa, address, .exclusive);32 const module = try si.findModule(gpa, address, .exclusive);
34 defer si.rwlock.unlock();33 defer si.rwlock.unlock();
3534
36 const vaddr = address - module.load_offset;35 const vaddr = address - module.load_offset;
3736
38 const loaded_elf = try module.getLoadedElf(gpa);37 const loaded_elf = try module.getLoadedElf(gpa, io);
39 if (loaded_elf.file.dwarf) |*dwarf| {38 if (loaded_elf.file.dwarf) |*dwarf| {
40 if (!loaded_elf.scanned_dwarf) {39 if (!loaded_elf.scanned_dwarf) {
41 dwarf.open(gpa, native_endian) catch |err| switch (err) {40 dwarf.open(gpa, native_endian) catch |err| switch (err) {
...@@ -180,7 +179,7 @@ comptime {...@@ -180,7 +179,7 @@ comptime {
180 }179 }
181}180}
182pub const UnwindContext = Dwarf.SelfUnwinder;181pub 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 {
184 comptime assert(can_unwind);183 comptime assert(can_unwind);
185184
186 {185 {
...@@ -201,7 +200,7 @@ pub fn unwindFrame(si: *SelfInfo, gpa: Allocator, context: *UnwindContext) Error...@@ -201,7 +200,7 @@ pub fn unwindFrame(si: *SelfInfo, gpa: Allocator, context: *UnwindContext) Error
201 @memset(si.unwind_cache.?, .empty);200 @memset(si.unwind_cache.?, .empty);
202 }201 }
203202
204 const unwind_sections = try module.getUnwindSections(gpa);203 const unwind_sections = try module.getUnwindSections(gpa, io);
205 for (unwind_sections) |*unwind| {204 for (unwind_sections) |*unwind| {
206 if (context.computeRules(gpa, unwind, module.load_offset, null)) |entry| {205 if (context.computeRules(gpa, unwind, module.load_offset, null)) |entry| {
207 entry.populate(si.unwind_cache.?);206 entry.populate(si.unwind_cache.?);
...@@ -261,12 +260,12 @@ const Module = struct {...@@ -261,12 +260,12 @@ const Module = struct {
261 };260 };
262261
263 /// Assumes we already hold an exclusive lock.262 /// Assumes we already hold an exclusive lock.
264 fn getUnwindSections(mod: *Module, gpa: Allocator) Error![]Dwarf.Unwind {263 fn getUnwindSections(mod: *Module, gpa: Allocator, io: Io) Error![]Dwarf.Unwind {
265 if (mod.unwind == null) mod.unwind = loadUnwindSections(mod, gpa);264 if (mod.unwind == null) mod.unwind = loadUnwindSections(mod, gpa, io);
266 const us = &(mod.unwind.? catch |err| return err);265 const us = &(mod.unwind.? catch |err| return err);
267 return us.buf[0..us.len];266 return us.buf[0..us.len];
268 }267 }
269 fn loadUnwindSections(mod: *Module, gpa: Allocator) Error!UnwindSections {268 fn loadUnwindSections(mod: *Module, gpa: Allocator, io: Io) Error!UnwindSections {
270 var us: UnwindSections = .{269 var us: UnwindSections = .{
271 .buf = undefined,270 .buf = undefined,
272 .len = 0,271 .len = 0,
...@@ -284,7 +283,7 @@ const Module = struct {...@@ -284,7 +283,7 @@ const Module = struct {
284 } else {283 } else {
285 // There is no `.eh_frame_hdr` section. There may still be an `.eh_frame` or `.debug_frame`284 // There is no `.eh_frame_hdr` section. There may still be an `.eh_frame` or `.debug_frame`
286 // section, but we'll have to load the binary to get at it.285 // 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);
288 // If both are present, we can't just pick one -- the info could be split between them.287 // If both are present, we can't just pick one -- the info could be split between them.
289 // `.debug_frame` is likely to be the more complete section, so we'll prioritize that one.288 // `.debug_frame` is likely to be the more complete section, so we'll prioritize that one.
290 if (loaded.file.debug_frame) |*debug_frame| {289 if (loaded.file.debug_frame) |*debug_frame| {
...@@ -325,7 +324,7 @@ const Module = struct {...@@ -325,7 +324,7 @@ const Module = struct {
325 }324 }
326 fn loadElf(mod: *Module, gpa: Allocator, io: Io) Error!LoadedElf {325 fn loadElf(mod: *Module, gpa: Allocator, io: Io) Error!LoadedElf {
327 const load_result = if (mod.name.len > 0) res: {326 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;
329 defer file.close(io);328 defer file.close(io);
330 break :res std.debug.ElfFile.load(gpa, file, mod.build_id, &.native(mod.name));329 break :res std.debug.ElfFile.load(gpa, file, mod.build_id, &.native(mod.name));
331 } else res: {330 } else res: {
...@@ -334,7 +333,7 @@ const Module = struct {...@@ -334,7 +333,7 @@ const Module = struct {
334 else => return error.ReadFailed,333 else => return error.ReadFailed,
335 };334 };
336 defer gpa.free(path);335 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;
338 defer file.close(io);337 defer file.close(io);
339 break :res std.debug.ElfFile.load(gpa, file, mod.build_id, &.native(path));338 break :res std.debug.ElfFile.load(gpa, file, mod.build_id, &.native(path));
340 };339 };
lib/std/debug/SelfInfo/MachO.zig+1-1
...@@ -616,7 +616,7 @@ test {...@@ -616,7 +616,7 @@ test {
616616
617/// Uses `mmap` to map the file at `path` into memory.617/// Uses `mmap` to map the file at `path` into memory.
618fn mapDebugInfoFile(io: Io, path: []const u8) ![]align(std.heap.page_size_min) const u8 {618fn 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) {
620 error.FileNotFound => return error.MissingDebugInfo,620 error.FileNotFound => return error.MissingDebugInfo,
621 else => return error.ReadFailed,621 else => return error.ReadFailed,
622 };622 };
lib/std/debug/SelfInfo/Windows.zig+2-2
...@@ -432,7 +432,7 @@ const Module = struct {...@@ -432,7 +432,7 @@ const Module = struct {
432 break :pdb null;432 break :pdb null;
433 };433 };
434 const pdb_file_open_result = if (fs.path.isAbsolute(path)) res: {434 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, .{});
436 } else res: {436 } else res: {
437 const self_dir = std.process.executableDirPathAlloc(io, gpa) catch |err| switch (err) {437 const self_dir = std.process.executableDirPathAlloc(io, gpa) catch |err| switch (err) {
438 error.OutOfMemory, error.Unexpected => |e| return e,438 error.OutOfMemory, error.Unexpected => |e| return e,
...@@ -441,7 +441,7 @@ const Module = struct {...@@ -441,7 +441,7 @@ const Module = struct {
441 defer gpa.free(self_dir);441 defer gpa.free(self_dir);
442 const abs_path = try fs.path.join(gpa, &.{ self_dir, path });442 const abs_path = try fs.path.join(gpa, &.{ self_dir, path });
443 defer gpa.free(abs_path);443 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, .{});
445 };445 };
446 const pdb_file = pdb_file_open_result catch |err| switch (err) {446 const pdb_file = pdb_file_open_result catch |err| switch (err) {
447 error.FileNotFound, error.IsDir => break :pdb null,447 error.FileNotFound, error.IsDir => break :pdb null,
lib/std/dynamic_library.zig+4-4
...@@ -160,7 +160,7 @@ pub const ElfDynLib = struct {...@@ -160,7 +160,7 @@ pub const ElfDynLib = struct {
160 fn openPath(path: []const u8, io: Io) !Io.Dir {160 fn openPath(path: []const u8, io: Io) !Io.Dir {
161 if (path.len == 0) return error.NotDir;161 if (path.len == 0) return error.NotDir;
162 var parts = std.mem.tokenizeScalar(u8, path, '/');162 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();
164 while (parts.next()) |part| {164 while (parts.next()) |part| {
165 const child = try parent.openDir(part, .{});165 const child = try parent.openDir(part, .{});
166 parent.close(io);166 parent.close(io);
...@@ -174,7 +174,7 @@ pub const ElfDynLib = struct {...@@ -174,7 +174,7 @@ pub const ElfDynLib = struct {
174 while (paths.next()) |p| {174 while (paths.next()) |p| {
175 var dir = openPath(p) catch continue;175 var dir = openPath(p) catch continue;
176 defer dir.close(io);176 defer dir.close(io);
177 const fd = posix.openat(dir.fd, file_name, .{177 const fd = posix.openat(dir.handle, file_name, .{
178 .ACCMODE = .RDONLY,178 .ACCMODE = .RDONLY,
179 .CLOEXEC = true,179 .CLOEXEC = true,
180 }, 0) catch continue;180 }, 0) catch continue;
...@@ -184,9 +184,9 @@ pub const ElfDynLib = struct {...@@ -184,9 +184,9 @@ pub const ElfDynLib = struct {
184 }184 }
185185
186 fn resolveFromParent(io: Io, dir_path: []const u8, file_name: []const u8) ?posix.fd_t {186 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;
188 defer dir.close(io);188 defer dir.close(io);
189 return posix.openat(dir.fd, file_name, .{189 return posix.openat(dir.handle, file_name, .{
190 .ACCMODE = .RDONLY,190 .ACCMODE = .RDONLY,
191 .CLOEXEC = true,191 .CLOEXEC = true,
192 }, 0) catch null;192 }, 0) catch null;
lib/std/fs/test.zig+54-62
...@@ -46,7 +46,7 @@ const PathType = enum {...@@ -46,7 +46,7 @@ const PathType = enum {
46 // The final path may not actually exist which would cause realpath to fail.46 // The final path may not actually exist which would cause realpath to fail.
47 // So instead, we get the path of the dir and join it with the relative path.47 // So instead, we get the path of the dir and join it with the relative path.
48 var fd_path_buf: [fs.max_path_bytes]u8 = undefined;48 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);
50 return fs.path.joinZ(allocator, &.{ dir_path, relative_path });50 return fs.path.joinZ(allocator, &.{ dir_path, relative_path });
51 }51 }
52 }.transform,52 }.transform,
...@@ -55,7 +55,7 @@ const PathType = enum {...@@ -55,7 +55,7 @@ const PathType = enum {
55 // Any drive absolute path (C:\foo) can be converted into a UNC path by55 // Any drive absolute path (C:\foo) can be converted into a UNC path by
56 // using '127.0.0.1' as the server name and '<drive letter>$' as the share name.56 // using '127.0.0.1' as the server name and '<drive letter>$' as the share name.
57 var fd_path_buf: [fs.max_path_bytes]u8 = undefined;57 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);
59 const windows_path_type = windows.getWin32PathType(u8, dir_path);59 const windows_path_type = windows.getWin32PathType(u8, dir_path);
60 switch (windows_path_type) {60 switch (windows_path_type) {
61 .unc_absolute => return fs.path.joinZ(allocator, &.{ dir_path, relative_path }),61 .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...@@ -256,7 +256,7 @@ fn testReadLinkW(allocator: mem.Allocator, dir: Dir, target_path: []const u8, sy
256 const target_path_w = try std.unicode.wtf8ToWtf16LeAlloc(allocator, target_path);256 const target_path_w = try std.unicode.wtf8ToWtf16LeAlloc(allocator, target_path);
257 defer allocator.free(target_path_w);257 defer allocator.free(target_path_w);
258 // Calling the W functions directly requires the path to be NT-prefixed258 // 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);
260 const wtf16_buffer = try allocator.alloc(u16, target_path_w.len);260 const wtf16_buffer = try allocator.alloc(u16, target_path_w.len);
261 defer allocator.free(wtf16_buffer);261 defer allocator.free(wtf16_buffer);
262 const actual = try dir.readLinkW(symlink_path_w.span(), wtf16_buffer);262 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" {...@@ -288,9 +288,11 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {
288288
289 var symlink: Dir = switch (builtin.target.os.tag) {289 var symlink: Dir = switch (builtin.target.os.tag) {
290 .windows => windows_symlink: {290 .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
295 const path_len_bytes = @as(u16, @intCast(sub_path_w.span().len * 2));297 const path_len_bytes = @as(u16, @intCast(sub_path_w.span().len * 2));
296 var nt_name = windows.UNICODE_STRING{298 var nt_name = windows.UNICODE_STRING{
...@@ -300,26 +302,16 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {...@@ -300,26 +302,16 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {
300 };302 };
301 var attr: windows.OBJECT_ATTRIBUTES = .{303 var attr: windows.OBJECT_ATTRIBUTES = .{
302 .Length = @sizeOf(windows.OBJECT_ATTRIBUTES),304 .Length = @sizeOf(windows.OBJECT_ATTRIBUTES),
303 .RootDirectory = if (fs.path.isAbsoluteWindowsW(sub_path_w.span())) null else ctx.dir.fd,305 .RootDirectory = if (fs.path.isAbsoluteWindowsW(sub_path_w.span())) null else ctx.dir.handle,
304 .Attributes = .{},306 .Attributes = 0,
305 .ObjectName = &nt_name,307 .ObjectName = &nt_name,
306 .SecurityDescriptor = null,308 .SecurityDescriptor = null,
307 .SecurityQualityOfService = null,309 .SecurityQualityOfService = null,
308 };310 };
309 var io_status_block: windows.IO_STATUS_BLOCK = undefined;311 var io_status_block: windows.IO_STATUS_BLOCK = undefined;
310 const rc = windows.ntdll.NtCreateFile(312 const rc = windows.ntdll.NtCreateFile(
311 &handle,313 &result.handle,
312 .{314 windows.STANDARD_RIGHTS_READ | windows.FILE_READ_ATTRIBUTES | windows.FILE_READ_EA | windows.SYNCHRONIZE | windows.FILE_TRAVERSE,
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 },
323 &attr,315 &attr,
324 &io_status_block,316 &io_status_block,
325 null,317 null,
...@@ -337,7 +329,7 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {...@@ -337,7 +329,7 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {
337 );329 );
338330
339 switch (rc) {331 switch (rc) {
340 .SUCCESS => break :windows_symlink .{ .fd = handle },332 .SUCCESS => break :windows_symlink .{ .fd = result.handle },
341 else => return windows.unexpectedStatus(rc),333 else => return windows.unexpectedStatus(rc),
342 }334 }
343 },335 },
...@@ -351,8 +343,8 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {...@@ -351,8 +343,8 @@ test "File.stat on a File that is a symlink returns Kind.sym_link" {
351 .ACCMODE = .RDONLY,343 .ACCMODE = .RDONLY,
352 .CLOEXEC = true,344 .CLOEXEC = true,
353 };345 };
354 const fd = try posix.openatZ(ctx.dir.fd, &sub_path_c, flags, 0);346 const fd = try posix.openatZ(ctx.dir.handle, &sub_path_c, flags, 0);
355 break :linux_symlink Dir{ .fd = fd };347 break :linux_symlink .{ .handle = fd };
356 },348 },
357 else => unreachable,349 else => unreachable,
358 };350 };
...@@ -456,7 +448,7 @@ test "openDirAbsolute" {...@@ -456,7 +448,7 @@ test "openDirAbsolute" {
456test "openDir cwd parent '..'" {448test "openDir cwd parent '..'" {
457 const io = testing.io;449 const io = testing.io;
458450
459 var dir = fs.cwd().openDir("..", .{}) catch |err| {451 var dir = Io.Dir.cwd().openDir("..", .{}) catch |err| {
460 if (native_os == .wasi and err == error.PermissionDenied) {452 if (native_os == .wasi and err == error.PermissionDenied) {
461 return; // This is okay. WASI disallows escaping from the fs sandbox453 return; // This is okay. WASI disallows escaping from the fs sandbox
462 }454 }
...@@ -534,7 +526,7 @@ test "Dir.Iterator" {...@@ -534,7 +526,7 @@ test "Dir.Iterator" {
534 defer tmp_dir.cleanup();526 defer tmp_dir.cleanup();
535527
536 // First, create a couple of entries to iterate over.528 // 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", .{});
538 file.close(io);530 file.close(io);
539531
540 try tmp_dir.dir.makeDir("some_dir");532 try tmp_dir.dir.makeDir("some_dir");
...@@ -570,7 +562,7 @@ test "Dir.Iterator many entries" {...@@ -570,7 +562,7 @@ test "Dir.Iterator many entries" {
570 var buf: [4]u8 = undefined; // Enough to store "1024".562 var buf: [4]u8 = undefined; // Enough to store "1024".
571 while (i < num) : (i += 1) {563 while (i < num) : (i += 1) {
572 const name = try std.fmt.bufPrint(&buf, "{}", .{i});564 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, .{});
574 file.close(io);566 file.close(io);
575 }567 }
576568
...@@ -603,7 +595,7 @@ test "Dir.Iterator twice" {...@@ -603,7 +595,7 @@ test "Dir.Iterator twice" {
603 defer tmp_dir.cleanup();595 defer tmp_dir.cleanup();
604596
605 // First, create a couple of entries to iterate over.597 // 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", .{});
607 file.close(io);599 file.close(io);
608600
609 try tmp_dir.dir.makeDir("some_dir");601 try tmp_dir.dir.makeDir("some_dir");
...@@ -638,7 +630,7 @@ test "Dir.Iterator reset" {...@@ -638,7 +630,7 @@ test "Dir.Iterator reset" {
638 defer tmp_dir.cleanup();630 defer tmp_dir.cleanup();
639631
640 // First, create a couple of entries to iterate over.632 // 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", .{});
642 file.close(io);634 file.close(io);
643635
644 try tmp_dir.dir.makeDir("some_dir");636 try tmp_dir.dir.makeDir("some_dir");
...@@ -769,7 +761,7 @@ test "readFileAlloc" {...@@ -769,7 +761,7 @@ test "readFileAlloc" {
769 var tmp_dir = tmpDir(.{});761 var tmp_dir = tmpDir(.{});
770 defer tmp_dir.cleanup();762 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 });
773 defer file.close(io);765 defer file.close(io);
774766
775 const buf1 = try tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(1024));767 const buf1 = try tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(1024));
...@@ -843,7 +835,7 @@ test "directory operations on files" {...@@ -843,7 +835,7 @@ test "directory operations on files" {
843835
844 const test_file_name = try ctx.transformPath("test_file");836 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 });
847 file.close(io);839 file.close(io);
848840
849 try testing.expectError(error.PathAlreadyExists, ctx.dir.makeDir(test_file_name));841 try testing.expectError(error.PathAlreadyExists, ctx.dir.makeDir(test_file_name));
...@@ -876,7 +868,7 @@ test "file operations on directories" {...@@ -876,7 +868,7 @@ test "file operations on directories" {
876868
877 try ctx.dir.makeDir(test_dir_name);869 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, .{}));
880 try testing.expectError(error.IsDir, ctx.dir.deleteFile(test_dir_name));872 try testing.expectError(error.IsDir, ctx.dir.deleteFile(test_dir_name));
881 switch (native_os) {873 switch (native_os) {
882 .dragonfly, .netbsd => {874 .dragonfly, .netbsd => {
...@@ -969,7 +961,7 @@ test "Dir.rename files" {...@@ -969,7 +961,7 @@ test "Dir.rename files" {
969 // Renaming files961 // Renaming files
970 const test_file_name = try ctx.transformPath("test_file");962 const test_file_name = try ctx.transformPath("test_file");
971 const renamed_test_file_name = try ctx.transformPath("test_file_renamed");963 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 });
973 file.close(io);965 file.close(io);
974 try ctx.dir.rename(test_file_name, renamed_test_file_name);966 try ctx.dir.rename(test_file_name, renamed_test_file_name);
975967
...@@ -983,7 +975,7 @@ test "Dir.rename files" {...@@ -983,7 +975,7 @@ test "Dir.rename files" {
983975
984 // Rename to existing file succeeds976 // Rename to existing file succeeds
985 const existing_file_path = try ctx.transformPath("existing_file");977 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 });
987 existing_file.close(io);979 existing_file.close(io);
988 try ctx.dir.rename(renamed_test_file_name, existing_file_path);980 try ctx.dir.rename(renamed_test_file_name, existing_file_path);
989981
...@@ -1017,7 +1009,7 @@ test "Dir.rename directories" {...@@ -1017,7 +1009,7 @@ test "Dir.rename directories" {
1017 var dir = try ctx.dir.openDir(test_dir_renamed_path, .{});1009 var dir = try ctx.dir.openDir(test_dir_renamed_path, .{});
10181010
1019 // Put a file in the directory1011 // 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 });
1021 file.close(io);1013 file.close(io);
1022 dir.close(io);1014 dir.close(io);
10231015
...@@ -1070,7 +1062,7 @@ test "Dir.rename directory onto non-empty dir" {...@@ -1070,7 +1062,7 @@ test "Dir.rename directory onto non-empty dir" {
1070 try ctx.dir.makeDir(test_dir_path);1062 try ctx.dir.makeDir(test_dir_path);
10711063
1072 var target_dir = try ctx.dir.makeOpenPath(target_dir_path, .{});1064 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 });
1074 file.close(io);1066 file.close(io);
1075 target_dir.close(io);1067 target_dir.close(io);
10761068
...@@ -1094,7 +1086,7 @@ test "Dir.rename file <-> dir" {...@@ -1094,7 +1086,7 @@ test "Dir.rename file <-> dir" {
1094 const test_file_path = try ctx.transformPath("test_file");1086 const test_file_path = try ctx.transformPath("test_file");
1095 const test_dir_path = try ctx.transformPath("test_dir");1087 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 });
1098 file.close(io);1090 file.close(io);
1099 try ctx.dir.makeDir(test_dir_path);1091 try ctx.dir.makeDir(test_dir_path);
1100 try testing.expectError(error.IsDir, ctx.dir.rename(test_file_path, test_dir_path));1092 try testing.expectError(error.IsDir, ctx.dir.rename(test_file_path, test_dir_path));
...@@ -1115,7 +1107,7 @@ test "rename" {...@@ -1115,7 +1107,7 @@ test "rename" {
1115 // Renaming files1107 // Renaming files
1116 const test_file_name = "test_file";1108 const test_file_name = "test_file";
1117 const renamed_test_file_name = "test_file_renamed";1109 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 });
1119 file.close(io);1111 file.close(io);
1120 try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name);1112 try fs.rename(tmp_dir1.dir, test_file_name, tmp_dir2.dir, renamed_test_file_name);
11211113
...@@ -1149,7 +1141,7 @@ test "renameAbsolute" {...@@ -1149,7 +1141,7 @@ test "renameAbsolute" {
1149 // Renaming files1141 // Renaming files
1150 const test_file_name = "test_file";1142 const test_file_name = "test_file";
1151 const renamed_test_file_name = "test_file_renamed";1143 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 });
1153 file.close(io);1145 file.close(io);
1154 try fs.renameAbsolute(1146 try fs.renameAbsolute(
1155 try fs.path.join(allocator, &.{ base_path, test_file_name }),1147 try fs.path.join(allocator, &.{ base_path, test_file_name }),
...@@ -1454,7 +1446,7 @@ test "writev, readv" {...@@ -1454,7 +1446,7 @@ test "writev, readv" {
1454 var write_vecs: [2][]const u8 = .{ line1, line2 };1446 var write_vecs: [2][]const u8 = .{ line1, line2 };
1455 var read_vecs: [2][]u8 = .{ &buf2, &buf1 };1447 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 });
1458 defer src_file.close(io);1450 defer src_file.close(io);
14591451
1460 var writer = src_file.writerStreaming(&.{});1452 var writer = src_file.writerStreaming(&.{});
...@@ -1484,7 +1476,7 @@ test "pwritev, preadv" {...@@ -1484,7 +1476,7 @@ test "pwritev, preadv" {
1484 var buf2: [line2.len]u8 = undefined;1476 var buf2: [line2.len]u8 = undefined;
1485 var read_vecs: [2][]u8 = .{ &buf2, &buf1 };1477 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 });
1488 defer src_file.close(io);1480 defer src_file.close(io);
14891481
1490 var writer = src_file.writer(&.{});1482 var writer = src_file.writer(&.{});
...@@ -1584,14 +1576,14 @@ test "sendfile" {...@@ -1584,14 +1576,14 @@ test "sendfile" {
1584 const line2 = "second line\n";1576 const line2 = "second line\n";
1585 var vecs = [_][]const u8{ line1, line2 };1577 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 });
1588 defer src_file.close(io);1580 defer src_file.close(io);
1589 {1581 {
1590 var fw = src_file.writer(&.{});1582 var fw = src_file.writer(&.{});
1591 try fw.interface.writeVecAll(&vecs);1583 try fw.interface.writeVecAll(&vecs);
1592 }1584 }
15931585
1594 var dest_file = try dir.createFile("sendfile2.txt", .{ .read = true });1586 var dest_file = try dir.createFile(io, "sendfile2.txt", .{ .read = true });
1595 defer dest_file.close(io);1587 defer dest_file.close(io);
15961588
1597 const header1 = "header1\n";1589 const header1 = "header1\n";
...@@ -1627,12 +1619,12 @@ test "sendfile with buffered data" {...@@ -1627,12 +1619,12 @@ test "sendfile with buffered data" {
1627 var dir = try tmp.dir.openDir("os_test_tmp", .{});1619 var dir = try tmp.dir.openDir("os_test_tmp", .{});
1628 defer dir.close(io);1620 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 });
1631 defer src_file.close(io);1623 defer src_file.close(io);
16321624
1633 try src_file.writeAll("AAAABBBB");1625 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 });
1636 defer dest_file.close(io);1628 defer dest_file.close(io);
16371629
1638 var src_buffer: [32]u8 = undefined;1630 var src_buffer: [32]u8 = undefined;
...@@ -1718,10 +1710,10 @@ test "open file with exclusive nonblocking lock twice" {...@@ -1718,10 +1710,10 @@ test "open file with exclusive nonblocking lock twice" {
1718 const io = ctx.io;1710 const io = ctx.io;
1719 const filename = try ctx.transformPath("file_nonblocking_lock_test.txt");1711 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 });
1722 defer file1.close(io);1714 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 });
1725 try testing.expectError(error.WouldBlock, file2);1717 try testing.expectError(error.WouldBlock, file2);
1726 }1718 }
1727 }.impl);1719 }.impl);
...@@ -1735,10 +1727,10 @@ test "open file with shared and exclusive nonblocking lock" {...@@ -1735,10 +1727,10 @@ test "open file with shared and exclusive nonblocking lock" {
1735 const io = ctx.io;1727 const io = ctx.io;
1736 const filename = try ctx.transformPath("file_nonblocking_lock_test.txt");1728 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 });
1739 defer file1.close(io);1731 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 });
1742 try testing.expectError(error.WouldBlock, file2);1734 try testing.expectError(error.WouldBlock, file2);
1743 }1735 }
1744 }.impl);1736 }.impl);
...@@ -1752,10 +1744,10 @@ test "open file with exclusive and shared nonblocking lock" {...@@ -1752,10 +1744,10 @@ test "open file with exclusive and shared nonblocking lock" {
1752 const io = ctx.io;1744 const io = ctx.io;
1753 const filename = try ctx.transformPath("file_nonblocking_lock_test.txt");1745 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 });
1756 defer file1.close(io);1748 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 });
1759 try testing.expectError(error.WouldBlock, file2);1751 try testing.expectError(error.WouldBlock, file2);
1760 }1752 }
1761 }.impl);1753 }.impl);
...@@ -1769,13 +1761,13 @@ test "open file with exclusive lock twice, make sure second lock waits" {...@@ -1769,13 +1761,13 @@ test "open file with exclusive lock twice, make sure second lock waits" {
1769 const io = ctx.io;1761 const io = ctx.io;
1770 const filename = try ctx.transformPath("file_lock_test.txt");1762 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 });
1773 errdefer file.close(io);1765 errdefer file.close(io);
17741766
1775 const S = struct {1767 const S = struct {
1776 fn checkFn(dir: *Io.Dir, path: []const u8, started: *std.Thread.ResetEvent, locked: *std.Thread.ResetEvent) !void {1768 fn checkFn(dir: *Io.Dir, path: []const u8, started: *std.Thread.ResetEvent, locked: *std.Thread.ResetEvent) !void {
1777 started.set();1769 started.set();
1778 const file1 = try dir.createFile(path, .{ .lock = .exclusive });1770 const file1 = try dir.createFile(io, path, .{ .lock = .exclusive });
17791771
1780 locked.set();1772 locked.set();
1781 file1.close(io);1773 file1.close(io);
...@@ -1847,13 +1839,13 @@ test "read from locked file" {...@@ -1847,13 +1839,13 @@ test "read from locked file" {
1847 const filename = try ctx.transformPath("read_lock_file_test.txt");1839 const filename = try ctx.transformPath("read_lock_file_test.txt");
18481840
1849 {1841 {
1850 const f = try ctx.dir.createFile(filename, .{ .read = true });1842 const f = try ctx.dir.createFile(io, filename, .{ .read = true });
1851 defer f.close(io);1843 defer f.close(io);
1852 var buffer: [1]u8 = undefined;1844 var buffer: [1]u8 = undefined;
1853 _ = try f.read(&buffer);1845 _ = try f.read(&buffer);
1854 }1846 }
1855 {1847 {
1856 const f = try ctx.dir.createFile(filename, .{1848 const f = try ctx.dir.createFile(io, filename, .{
1857 .read = true,1849 .read = true,
1858 .lock = .exclusive,1850 .lock = .exclusive,
1859 });1851 });
...@@ -2037,7 +2029,7 @@ test "'.' and '..' in Io.Dir functions" {...@@ -2037,7 +2029,7 @@ test "'.' and '..' in Io.Dir functions" {
2037 var created_subdir = try ctx.dir.openDir(subdir_path, .{});2029 var created_subdir = try ctx.dir.openDir(subdir_path, .{});
2038 created_subdir.close(io);2030 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, .{});
2041 created_file.close(io);2033 created_file.close(io);
2042 try ctx.dir.access(file_path, .{});2034 try ctx.dir.access(file_path, .{});
20432035
...@@ -2103,7 +2095,7 @@ test "chmod" {...@@ -2103,7 +2095,7 @@ test "chmod" {
2103 var tmp = tmpDir(.{});2095 var tmp = tmpDir(.{});
2104 defer tmp.cleanup();2096 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 });
2107 defer file.close(io);2099 defer file.close(io);
2108 try testing.expectEqual(@as(File.Mode, 0o600), (try file.stat()).mode & 0o7777);2100 try testing.expectEqual(@as(File.Mode, 0o600), (try file.stat()).mode & 0o7777);
21092101
...@@ -2127,7 +2119,7 @@ test "chown" {...@@ -2127,7 +2119,7 @@ test "chown" {
2127 var tmp = tmpDir(.{});2119 var tmp = tmpDir(.{});
2128 defer tmp.cleanup();2120 defer tmp.cleanup();
21292121
2130 const file = try tmp.dir.createFile("test_file", .{});2122 const file = try tmp.dir.createFile(io, "test_file", .{});
2131 defer file.close(io);2123 defer file.close(io);
2132 try file.chown(null, null);2124 try file.chown(null, null);
21332125
...@@ -2228,7 +2220,7 @@ test "read file non vectored" {...@@ -2228,7 +2220,7 @@ test "read file non vectored" {
22282220
2229 const contents = "hello, world!\n";2221 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 });
2232 defer file.close(io);2224 defer file.close(io);
2233 {2225 {
2234 var file_writer: File.Writer = .init(file, &.{});2226 var file_writer: File.Writer = .init(file, &.{});
...@@ -2260,7 +2252,7 @@ test "seek keeping partial buffer" {...@@ -2260,7 +2252,7 @@ test "seek keeping partial buffer" {
22602252
2261 const contents = "0123456789";2253 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 });
2264 defer file.close(io);2256 defer file.close(io);
2265 {2257 {
2266 var file_writer: File.Writer = .init(file, &.{});2258 var file_writer: File.Writer = .init(file, &.{});
...@@ -2321,7 +2313,7 @@ test "seekTo flushes buffered data" {...@@ -2321,7 +2313,7 @@ test "seekTo flushes buffered data" {
23212313
2322 const contents = "data";2314 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 });
2325 defer file.close(io);2317 defer file.close(io);
2326 {2318 {
2327 var buf: [16]u8 = undefined;2319 var buf: [16]u8 = undefined;
...@@ -2350,7 +2342,7 @@ test "File.Writer sendfile with buffered contents" {...@@ -2350,7 +2342,7 @@ test "File.Writer sendfile with buffered contents" {
2350 try tmp_dir.dir.writeFile(.{ .sub_path = "a", .data = "bcd" });2342 try tmp_dir.dir.writeFile(.{ .sub_path = "a", .data = "bcd" });
2351 const in = try tmp_dir.dir.openFile(io, "a", .{});2343 const in = try tmp_dir.dir.openFile(io, "a", .{});
2352 defer in.close(io);2344 defer in.close(io);
2353 const out = try tmp_dir.dir.createFile("b", .{});2345 const out = try tmp_dir.dir.createFile(io, "b", .{});
2354 defer out.close(io);2346 defer out.close(io);
23552347
2356 var in_buf: [2]u8 = undefined;2348 var in_buf: [2]u8 = undefined;
...@@ -2397,7 +2389,7 @@ test "readlinkat" {...@@ -2397,7 +2389,7 @@ test "readlinkat" {
2397 // create a symbolic link2389 // create a symbolic link
2398 if (native_os == .windows) {2390 if (native_os == .windows) {
2399 std.os.windows.CreateSymbolicLink(2391 std.os.windows.CreateSymbolicLink(
2400 tmp.dir.fd,2392 tmp.dir.handle,
2401 &[_]u16{ 'l', 'i', 'n', 'k' },2393 &[_]u16{ 'l', 'i', 'n', 'k' },
2402 &[_:0]u16{ 'f', 'i', 'l', 'e', '.', 't', 'x', 't' },2394 &[_:0]u16{ 'f', 'i', 'l', 'e', '.', 't', 'x', 't' },
2403 false,2395 false,
...@@ -2407,7 +2399,7 @@ test "readlinkat" {...@@ -2407,7 +2399,7 @@ test "readlinkat" {
2407 else => return err,2399 else => return err,
2408 };2400 };
2409 } else {2401 } else {
2410 try posix.symlinkat("file.txt", tmp.dir.fd, "link");2402 try posix.symlinkat("file.txt", tmp.dir.handle, "link");
2411 }2403 }
24122404
2413 // read the link2405 // read the link
lib/std/os/linux/IoUring.zig+12-12
...@@ -1991,7 +1991,7 @@ test "writev/fsync/readv" {...@@ -1991,7 +1991,7 @@ test "writev/fsync/readv" {
1991 defer tmp.cleanup();1991 defer tmp.cleanup();
19921992
1993 const path = "test_io_uring_writev_fsync_readv";1993 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 });
1995 defer file.close(io);1995 defer file.close(io);
1996 const fd = file.handle;1996 const fd = file.handle;
19971997
...@@ -2062,7 +2062,7 @@ test "write/read" {...@@ -2062,7 +2062,7 @@ test "write/read" {
2062 var tmp = std.testing.tmpDir(.{});2062 var tmp = std.testing.tmpDir(.{});
2063 defer tmp.cleanup();2063 defer tmp.cleanup();
2064 const path = "test_io_uring_write_read";2064 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 });
2066 defer file.close(io);2066 defer file.close(io);
2067 const fd = file.handle;2067 const fd = file.handle;
20682068
...@@ -2110,12 +2110,12 @@ test "splice/read" {...@@ -2110,12 +2110,12 @@ test "splice/read" {
21102110
2111 var tmp = std.testing.tmpDir(.{});2111 var tmp = std.testing.tmpDir(.{});
2112 const path_src = "test_io_uring_splice_src";2112 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 });
2114 defer file_src.close(io);2114 defer file_src.close(io);
2115 const fd_src = file_src.handle;2115 const fd_src = file_src.handle;
21162116
2117 const path_dst = "test_io_uring_splice_dst";2117 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 });
2119 defer file_dst.close(io);2119 defer file_dst.close(io);
2120 const fd_dst = file_dst.handle;2120 const fd_dst = file_dst.handle;
21212121
...@@ -2185,7 +2185,7 @@ test "write_fixed/read_fixed" {...@@ -2185,7 +2185,7 @@ test "write_fixed/read_fixed" {
2185 defer tmp.cleanup();2185 defer tmp.cleanup();
21862186
2187 const path = "test_io_uring_write_read_fixed";2187 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 });
2189 defer file.close(io);2189 defer file.close(io);
2190 const fd = file.handle;2190 const fd = file.handle;
21912191
...@@ -2306,7 +2306,7 @@ test "close" {...@@ -2306,7 +2306,7 @@ test "close" {
2306 defer tmp.cleanup();2306 defer tmp.cleanup();
23072307
2308 const path = "test_io_uring_close";2308 const path = "test_io_uring_close";
2309 const file = try tmp.dir.createFile(path, .{});2309 const file = try tmp.dir.createFile(io, path, .{});
2310 errdefer file.close(io);2310 errdefer file.close(io);
23112311
2312 const sqe_close = try ring.close(0x44444444, file.handle);2312 const sqe_close = try ring.close(0x44444444, file.handle);
...@@ -2652,7 +2652,7 @@ test "fallocate" {...@@ -2652,7 +2652,7 @@ test "fallocate" {
2652 defer tmp.cleanup();2652 defer tmp.cleanup();
26532653
2654 const path = "test_io_uring_fallocate";2654 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 });
2656 defer file.close(io);2656 defer file.close(io);
26572657
2658 try testing.expectEqual(@as(u64, 0), (try file.stat()).size);2658 try testing.expectEqual(@as(u64, 0), (try file.stat()).size);
...@@ -2699,7 +2699,7 @@ test "statx" {...@@ -2699,7 +2699,7 @@ test "statx" {
2699 var tmp = std.testing.tmpDir(.{});2699 var tmp = std.testing.tmpDir(.{});
2700 defer tmp.cleanup();2700 defer tmp.cleanup();
2701 const path = "test_io_uring_statx";2701 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 });
2703 defer file.close(io);2703 defer file.close(io);
27042704
2705 try testing.expectEqual(@as(u64, 0), (try file.stat()).size);2705 try testing.expectEqual(@as(u64, 0), (try file.stat()).size);
...@@ -2969,7 +2969,7 @@ test "renameat" {...@@ -2969,7 +2969,7 @@ test "renameat" {
29692969
2970 // Write old file with data2970 // 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 });
2973 defer old_file.close(io);2973 defer old_file.close(io);
2974 try old_file.writeAll("hello");2974 try old_file.writeAll("hello");
29752975
...@@ -3028,7 +3028,7 @@ test "unlinkat" {...@@ -3028,7 +3028,7 @@ test "unlinkat" {
30283028
3029 // Write old file with data3029 // 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 });
3032 defer file.close(io);3032 defer file.close(io);
30333033
3034 // Submit unlinkat3034 // Submit unlinkat
...@@ -3125,7 +3125,7 @@ test "symlinkat" {...@@ -3125,7 +3125,7 @@ test "symlinkat" {
3125 const path = "test_io_uring_symlinkat";3125 const path = "test_io_uring_symlinkat";
3126 const link_path = "test_io_uring_symlinkat_link";3126 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 });
3129 defer file.close(io);3129 defer file.close(io);
31303130
3131 // Submit symlinkat3131 // Submit symlinkat
...@@ -3177,7 +3177,7 @@ test "linkat" {...@@ -3177,7 +3177,7 @@ test "linkat" {
31773177
3178 // Write file with data3178 // 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 });
3181 defer first_file.close(io);3181 defer first_file.close(io);
3182 try first_file.writeAll("hello");3182 try first_file.writeAll("hello");
31833183
lib/std/os/linux/test.zig+3-3
...@@ -18,7 +18,7 @@ test "fallocate" {...@@ -18,7 +18,7 @@ test "fallocate" {
18 defer tmp.cleanup();18 defer tmp.cleanup();
1919
20 const path = "test_fallocate";20 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 });
22 defer file.close(io);22 defer file.close(io);
2323
24 try expect((try file.stat()).size == 0);24 try expect((try file.stat()).size == 0);
...@@ -85,7 +85,7 @@ test "statx" {...@@ -85,7 +85,7 @@ test "statx" {
85 defer tmp.cleanup();85 defer tmp.cleanup();
8686
87 const tmp_file_name = "just_a_temporary_file.txt";87 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, .{});
89 defer file.close(io);89 defer file.close(io);
9090
91 var buf: linux.Statx = undefined;91 var buf: linux.Statx = undefined;
...@@ -121,7 +121,7 @@ test "fadvise" {...@@ -121,7 +121,7 @@ test "fadvise" {
121 defer tmp.cleanup();121 defer tmp.cleanup();
122122
123 const tmp_file_name = "temp_posix_fadvise.txt";123 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, .{});
125 defer file.close(io);125 defer file.close(io);
126126
127 var buf: [2048]u8 = undefined;127 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...@@ -4639,8 +4639,8 @@ pub fn wToPrefixedFileW(dir: ?HANDLE, path: [:0]const u16) Wtf16ToPrefixedFileWE
4639 break :path_to_get path;4639 break :path_to_get path;
4640 }4640 }
4641 // We can also skip GetFinalPathNameByHandle if the handle matches4641 // We can also skip GetFinalPathNameByHandle if the handle matches
4642 // the handle returned by fs.cwd()4642 // the handle returned by Io.Dir.cwd()
4643 if (dir.? == std.fs.cwd().fd) {4643 if (dir.? == Io.Dir.cwd().fd) {
4644 break :path_to_get path;4644 break :path_to_get path;
4645 }4645 }
4646 // At this point, we know we have a relative path that had too many4646 // At this point, we know we have a relative path that had too many
lib/std/posix.zig+7-7
...@@ -15,15 +15,16 @@...@@ -15,15 +15,16 @@
15//! deal with the exception.15//! deal with the exception.
1616
17const builtin = @import("builtin");17const builtin = @import("builtin");
18const root = @import("root");18const native_os = builtin.os.tag;
19
19const std = @import("std.zig");20const std = @import("std.zig");
21const Io = std.Io;
20const mem = std.mem;22const mem = std.mem;
21const fs = std.fs;23const fs = std.fs;
22const max_path_bytes = fs.max_path_bytes;24const max_path_bytes = std.fs.max_path_bytes;
23const maxInt = std.math.maxInt;25const maxInt = std.math.maxInt;
24const cast = std.math.cast;26const cast = std.math.cast;
25const assert = std.debug.assert;27const assert = std.debug.assert;
26const native_os = builtin.os.tag;
27const page_size_min = std.heap.page_size_min;28const page_size_min = std.heap.page_size_min;
2829
29test {30test {
...@@ -797,7 +798,6 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {...@@ -797,7 +798,6 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
797 .INTR => continue,798 .INTR => continue,
798 .INVAL => unreachable,799 .INVAL => unreachable,
799 .FAULT => unreachable,800 .FAULT => unreachable,
800 .SRCH => return error.ProcessNotFound,
801 .AGAIN => return error.WouldBlock,801 .AGAIN => return error.WouldBlock,
802 .CANCELED => return error.Canceled,802 .CANCELED => return error.Canceled,
803 .BADF => return error.NotOpenForReading, // Can be a race condition.803 .BADF => return error.NotOpenForReading, // Can be a race condition.
...@@ -917,7 +917,6 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {...@@ -917,7 +917,6 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize {
917 .INTR => continue,917 .INTR => continue,
918 .INVAL => return error.InvalidArgument,918 .INVAL => return error.InvalidArgument,
919 .FAULT => unreachable,919 .FAULT => unreachable,
920 .SRCH => return error.ProcessNotFound,
921 .AGAIN => return error.WouldBlock,920 .AGAIN => return error.WouldBlock,
922 .BADF => return error.NotOpenForWriting, // can be a race condition.921 .BADF => return error.NotOpenForWriting, // can be a race condition.
923 .DESTADDRREQ => unreachable, // `connect` was never called.922 .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 {...@@ -985,7 +984,8 @@ pub fn openZ(file_path: [*:0]const u8, flags: O, perm: mode_t) OpenError!fd_t {
985 .NFILE => return error.SystemFdQuotaExceeded,984 .NFILE => return error.SystemFdQuotaExceeded,
986 .NODEV => return error.NoDevice,985 .NODEV => return error.NoDevice,
987 .NOENT => return error.FileNotFound,986 .NOENT => return error.FileNotFound,
988 .SRCH => return error.ProcessNotFound,987 // Can happen on Linux when opening procfs files.
988 .SRCH => return error.FileNotFound,
989 .NOMEM => return error.SystemResources,989 .NOMEM => return error.SystemResources,
990 .NOSPC => return error.NoSpaceLeft,990 .NOSPC => return error.NoSpaceLeft,
991 .NOTDIR => return error.NotDir,991 .NOTDIR => return error.NotDir,
...@@ -1560,7 +1560,7 @@ pub fn mkdirZ(dir_path: [*:0]const u8, mode: mode_t) MakeDirError!void {...@@ -1560,7 +1560,7 @@ pub fn mkdirZ(dir_path: [*:0]const u8, mode: mode_t) MakeDirError!void {
1560pub fn mkdirW(dir_path_w: []const u16, mode: mode_t) MakeDirError!void {1560pub fn mkdirW(dir_path_w: []const u16, mode: mode_t) MakeDirError!void {
1561 _ = mode;1561 _ = mode;
1562 const sub_dir_handle = windows.OpenFile(dir_path_w, .{1562 const sub_dir_handle = windows.OpenFile(dir_path_w, .{
1563 .dir = fs.cwd().fd,1563 .dir = Io.Dir.cwd().handle,
1564 .access_mask = .{1564 .access_mask = .{
1565 .STANDARD = .{ .SYNCHRONIZE = true },1565 .STANDARD = .{ .SYNCHRONIZE = true },
1566 .GENERIC = .{ .READ = true },1566 .GENERIC = .{ .READ = true },
lib/std/posix/test.zig+26-26
...@@ -148,7 +148,7 @@ test "linkat with different directories" {...@@ -148,7 +148,7 @@ test "linkat with different directories" {
148 try tmp.dir.writeFile(.{ .sub_path = target_name, .data = "example" });148 try tmp.dir.writeFile(.{ .sub_path = target_name, .data = "example" });
149149
150 // Test 1: link from file in subdir back up to target in parent directory150 // 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
153 const efd = try tmp.dir.openFile(io, target_name, .{});153 const efd = try tmp.dir.openFile(io, target_name, .{});
154 defer efd.close(io);154 defer efd.close(io);
...@@ -164,7 +164,7 @@ test "linkat with different directories" {...@@ -164,7 +164,7 @@ test "linkat with different directories" {
164 }164 }
165165
166 // Test 2: remove link166 // Test 2: remove link
167 try posix.unlinkat(subdir.fd, link_name, 0);167 try posix.unlinkat(subdir.handle, link_name, 0);
168 _, const elink = try getLinkInfo(efd.handle);168 _, const elink = try getLinkInfo(efd.handle);
169 try testing.expectEqual(@as(posix.nlink_t, 1), elink);169 try testing.expectEqual(@as(posix.nlink_t, 1), elink);
170}170}
...@@ -373,7 +373,7 @@ test "mmap" {...@@ -373,7 +373,7 @@ test "mmap" {
373373
374 // Create a file used for testing mmap() calls with a file descriptor374 // Create a file used for testing mmap() calls with a file descriptor
375 {375 {
376 const file = try tmp.dir.createFile(test_out_file, .{});376 const file = try tmp.dir.createFile(io, test_out_file, .{});
377 defer file.close(io);377 defer file.close(io);
378378
379 var stream = file.writer(&.{});379 var stream = file.writer(&.{});
...@@ -444,7 +444,7 @@ test "fcntl" {...@@ -444,7 +444,7 @@ test "fcntl" {
444444
445 const test_out_file = "os_tmp_test";445 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, .{});
448 defer file.close(io);448 defer file.close(io);
449449
450 // Note: The test assumes createFile opens the file with CLOEXEC450 // Note: The test assumes createFile opens the file with CLOEXEC
...@@ -495,7 +495,7 @@ test "fsync" {...@@ -495,7 +495,7 @@ test "fsync" {
495 defer tmp.cleanup();495 defer tmp.cleanup();
496496
497 const test_out_file = "os_tmp_test";497 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, .{});
499 defer file.close(io);499 defer file.close(io);
500500
501 try posix.fsync(file.handle);501 try posix.fsync(file.handle);
...@@ -617,7 +617,7 @@ test "dup & dup2" {...@@ -617,7 +617,7 @@ test "dup & dup2" {
617 defer tmp.cleanup();617 defer tmp.cleanup();
618618
619 {619 {
620 var file = try tmp.dir.createFile("os_dup_test", .{});620 var file = try tmp.dir.createFile(io, "os_dup_test", .{});
621 defer file.close(io);621 defer file.close(io);
622622
623 var duped = Io.File{ .handle = try posix.dup(file.handle) };623 var duped = Io.File{ .handle = try posix.dup(file.handle) };
...@@ -659,7 +659,7 @@ test "writev longer than IOV_MAX" {...@@ -659,7 +659,7 @@ test "writev longer than IOV_MAX" {
659 var tmp = tmpDir(.{});659 var tmp = tmpDir(.{});
660 defer tmp.cleanup();660 defer tmp.cleanup();
661661
662 var file = try tmp.dir.createFile("pwritev", .{});662 var file = try tmp.dir.createFile(io, "pwritev", .{});
663 defer file.close(io);663 defer file.close(io);
664664
665 const iovecs = [_]posix.iovec_const{.{ .base = "a", .len = 1 }} ** (posix.IOV_MAX + 1);665 const iovecs = [_]posix.iovec_const{.{ .base = "a", .len = 1 }} ** (posix.IOV_MAX + 1);
...@@ -684,7 +684,7 @@ test "POSIX file locking with fcntl" {...@@ -684,7 +684,7 @@ test "POSIX file locking with fcntl" {
684 defer tmp.cleanup();684 defer tmp.cleanup();
685685
686 // Create a temporary lock file686 // 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 });
688 defer file.close(io);688 defer file.close(io);
689 try file.setEndPos(2);689 try file.setEndPos(2);
690 const fd = file.handle;690 const fd = file.handle;
...@@ -881,7 +881,7 @@ test "isatty" {...@@ -881,7 +881,7 @@ test "isatty" {
881 var tmp = tmpDir(.{});881 var tmp = tmpDir(.{});
882 defer tmp.cleanup();882 defer tmp.cleanup();
883883
884 var file = try tmp.dir.createFile("foo", .{});884 var file = try tmp.dir.createFile(io, "foo", .{});
885 defer file.close(io);885 defer file.close(io);
886886
887 try expectEqual(posix.isatty(file.handle), false);887 try expectEqual(posix.isatty(file.handle), false);
...@@ -893,7 +893,7 @@ test "pread with empty buffer" {...@@ -893,7 +893,7 @@ test "pread with empty buffer" {
893 var tmp = tmpDir(.{});893 var tmp = tmpDir(.{});
894 defer tmp.cleanup();894 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 });
897 defer file.close(io);897 defer file.close(io);
898898
899 const bytes = try a.alloc(u8, 0);899 const bytes = try a.alloc(u8, 0);
...@@ -909,7 +909,7 @@ test "write with empty buffer" {...@@ -909,7 +909,7 @@ test "write with empty buffer" {
909 var tmp = tmpDir(.{});909 var tmp = tmpDir(.{});
910 defer tmp.cleanup();910 defer tmp.cleanup();
911911
912 var file = try tmp.dir.createFile("write_empty", .{});912 var file = try tmp.dir.createFile(io, "write_empty", .{});
913 defer file.close(io);913 defer file.close(io);
914914
915 const bytes = try a.alloc(u8, 0);915 const bytes = try a.alloc(u8, 0);
...@@ -925,7 +925,7 @@ test "pwrite with empty buffer" {...@@ -925,7 +925,7 @@ test "pwrite with empty buffer" {
925 var tmp = tmpDir(.{});925 var tmp = tmpDir(.{});
926 defer tmp.cleanup();926 defer tmp.cleanup();
927927
928 var file = try tmp.dir.createFile("pwrite_empty", .{});928 var file = try tmp.dir.createFile(io, "pwrite_empty", .{});
929 defer file.close(io);929 defer file.close(io);
930930
931 const bytes = try a.alloc(u8, 0);931 const bytes = try a.alloc(u8, 0);
...@@ -965,35 +965,35 @@ test "fchmodat smoke test" {...@@ -965,35 +965,35 @@ test "fchmodat smoke test" {
965 var tmp = tmpDir(.{});965 var tmp = tmpDir(.{});
966 defer tmp.cleanup();966 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));
969 const fd = try posix.openat(969 const fd = try posix.openat(
970 tmp.dir.fd,970 tmp.dir.handle,
971 "regfile",971 "regfile",
972 .{ .ACCMODE = .WRONLY, .CREAT = true, .EXCL = true, .TRUNC = true },972 .{ .ACCMODE = .WRONLY, .CREAT = true, .EXCL = true, .TRUNC = true },
973 0o644,973 0o644,
974 );974 );
975 posix.close(fd);975 posix.close(fd);
976976
977 try posix.symlinkat("regfile", tmp.dir.fd, "symlink");977 try posix.symlinkat("regfile", tmp.dir.handle, "symlink");
978 const sym_mode = try getFileMode(tmp.dir.fd, "symlink");978 const sym_mode = try getFileMode(tmp.dir.handle, "symlink");
979979
980 try posix.fchmodat(tmp.dir.fd, "regfile", 0o640, 0);980 try posix.fchmodat(tmp.dir.handle, "regfile", 0o640, 0);
981 try expectMode(tmp.dir.fd, "regfile", 0o640);981 try expectMode(tmp.dir.handle, "regfile", 0o640);
982 try posix.fchmodat(tmp.dir.fd, "regfile", 0o600, posix.AT.SYMLINK_NOFOLLOW);982 try posix.fchmodat(tmp.dir.handle, "regfile", 0o600, posix.AT.SYMLINK_NOFOLLOW);
983 try expectMode(tmp.dir.fd, "regfile", 0o600);983 try expectMode(tmp.dir.handle, "regfile", 0o600);
984984
985 try posix.fchmodat(tmp.dir.fd, "symlink", 0o640, 0);985 try posix.fchmodat(tmp.dir.handle, "symlink", 0o640, 0);
986 try expectMode(tmp.dir.fd, "regfile", 0o640);986 try expectMode(tmp.dir.handle, "regfile", 0o640);
987 try expectMode(tmp.dir.fd, "symlink", sym_mode);987 try expectMode(tmp.dir.handle, "symlink", sym_mode);
988988
989 var test_link = true;989 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) {
991 error.OperationNotSupported => test_link = false,991 error.OperationNotSupported => test_link = false,
992 else => |e| return e,992 else => |e| return e,
993 };993 };
994 if (test_link)994 if (test_link)
995 try expectMode(tmp.dir.fd, "symlink", 0o600);995 try expectMode(tmp.dir.handle, "symlink", 0o600);
996 try expectMode(tmp.dir.fd, "regfile", 0o640);996 try expectMode(tmp.dir.handle, "regfile", 0o640);
997}997}
998998
999const CommonOpenFlags = packed struct {999const CommonOpenFlags = packed struct {
lib/std/process/Child.zig+1-1
...@@ -677,7 +677,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {...@@ -677,7 +677,7 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
677 setUpChildIo(self.stderr_behavior, stderr_pipe[1], posix.STDERR_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err);677 setUpChildIo(self.stderr_behavior, stderr_pipe[1], posix.STDERR_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err);
678678
679 if (self.cwd_dir) |cwd| {679 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);
681 } else if (self.cwd) |cwd| {681 } else if (self.cwd) |cwd| {
682 posix.chdir(cwd) catch |err| forkChildErrReport(err_pipe[1], err);682 posix.chdir(cwd) catch |err| forkChildErrReport(err_pipe[1], err);
683 }683 }
lib/std/std.zig+1-1
...@@ -114,7 +114,7 @@ pub const options: Options = if (@hasDecl(root, "std_options")) root.std_options...@@ -114,7 +114,7 @@ pub const options: Options = if (@hasDecl(root, "std_options")) root.std_options
114pub const Options = struct {114pub const Options = struct {
115 enable_segfault_handler: bool = debug.default_enable_segfault_handler,115 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.
118 wasiCwd: fn () os.wasi.fd_t = os.defaultWasiCwd,118 wasiCwd: fn () os.wasi.fd_t = os.defaultWasiCwd,
119119
120 /// The current log level.120 /// 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...@@ -610,7 +610,7 @@ pub fn pipeToFileSystem(io: Io, dir: Io.Dir, reader: *Io.Reader, options: PipeOp
610 }610 }
611 },611 },
612 .file => {612 .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| {
614 defer fs_file.close(io);614 defer fs_file.close(io);
615 var file_writer = fs_file.writer(&file_contents_buffer);615 var file_writer = fs_file.writer(&file_contents_buffer);
616 try it.streamRemaining(file, &file_writer.interface);616 try it.streamRemaining(file, &file_writer.interface);
...@@ -638,12 +638,12 @@ pub fn pipeToFileSystem(io: Io, dir: Io.Dir, reader: *Io.Reader, options: PipeOp...@@ -638,12 +638,12 @@ pub fn pipeToFileSystem(io: Io, dir: Io.Dir, reader: *Io.Reader, options: PipeOp
638 }638 }
639}639}
640640
641fn createDirAndFile(dir: Io.Dir, file_name: []const u8, mode: Io.File.Mode) !Io.File {641fn createDirAndFile(io: Io, 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| {642 const fs_file = dir.createFile(io, file_name, .{ .exclusive = true, .mode = mode }) catch |err| {
643 if (err == error.FileNotFound) {643 if (err == error.FileNotFound) {
644 if (std.fs.path.dirname(file_name)) |dir_name| {644 if (std.fs.path.dirname(file_name)) |dir_name| {
645 try dir.makePath(dir_name);645 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 });
647 }647 }
648 }648 }
649 return err;649 return err;
...@@ -880,9 +880,9 @@ test "create file and symlink" {...@@ -880,9 +880,9 @@ test "create file and symlink" {
880 var root = testing.tmpDir(.{});880 var root = testing.tmpDir(.{});
881 defer root.cleanup();881 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);
884 file.close(io);884 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);
886 file.close(io);886 file.close(io);
887887
888 createDirAndSymlink(root.dir, "a/b/c/file2", "symlink1") catch |err| {888 createDirAndSymlink(root.dir, "a/b/c/file2", "symlink1") catch |err| {
...@@ -894,7 +894,7 @@ test "create file and symlink" {...@@ -894,7 +894,7 @@ test "create file and symlink" {
894894
895 // Danglink symlnik, file created later895 // Danglink symlnik, file created later
896 try createDirAndSymlink(root.dir, "../../../g/h/i/file4", "j/k/l/symlink3");896 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);
898 file.close(io);898 file.close(io);
899}899}
900900
lib/std/testing.zig+1-1
...@@ -628,7 +628,7 @@ pub fn tmpDir(opts: Io.Dir.OpenOptions) TmpDir {...@@ -628,7 +628,7 @@ pub fn tmpDir(opts: Io.Dir.OpenOptions) TmpDir {
628 var sub_path: [TmpDir.sub_path_len]u8 = undefined;628 var sub_path: [TmpDir.sub_path_len]u8 = undefined;
629 _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);629 _ = std.fs.base64_encoder.encode(&sub_path, &random_bytes);
630630
631 const cwd = std.fs.cwd();631 const cwd = Io.Dir.cwd();
632 var cache_dir = cwd.makeOpenPath(".zig-cache", .{}) catch632 var cache_dir = cwd.makeOpenPath(".zig-cache", .{}) catch
633 @panic("unable to make tmp dir for testing: unable to make and open .zig-cache dir");633 @panic("unable to make tmp dir for testing: unable to make and open .zig-cache dir");
634 defer cache_dir.close(io);634 defer cache_dir.close(io);
lib/std/zig/LibCInstallation.zig+6-6
...@@ -57,7 +57,7 @@ pub fn parse(...@@ -57,7 +57,7 @@ pub fn parse(
57 }57 }
58 }58 }
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)));
61 defer allocator.free(contents);61 defer allocator.free(contents);
6262
63 var it = std.mem.tokenizeScalar(u8, contents, '\n');63 var it = std.mem.tokenizeScalar(u8, contents, '\n');
...@@ -337,7 +337,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, args: FindNativeOptions) F...@@ -337,7 +337,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, args: FindNativeOptions) F
337 // search in reverse order337 // search in reverse order
338 const search_path_untrimmed = search_paths.items[search_paths.items.len - path_i - 1];338 const search_path_untrimmed = search_paths.items[search_paths.items.len - path_i - 1];
339 const search_path = std.mem.trimStart(u8, search_path_untrimmed, " ");339 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) {
341 error.FileNotFound,341 error.FileNotFound,
342 error.NotDir,342 error.NotDir,
343 error.NoDevice,343 error.NoDevice,
...@@ -392,7 +392,7 @@ fn findNativeIncludeDirWindows(...@@ -392,7 +392,7 @@ fn findNativeIncludeDirWindows(
392 result_buf.shrinkAndFree(0);392 result_buf.shrinkAndFree(0);
393 try result_buf.print("{s}\\Include\\{s}\\ucrt", .{ install.path, install.version });393 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) {
396 error.FileNotFound,396 error.FileNotFound,
397 error.NotDir,397 error.NotDir,
398 error.NoDevice,398 error.NoDevice,
...@@ -440,7 +440,7 @@ fn findNativeCrtDirWindows(...@@ -440,7 +440,7 @@ fn findNativeCrtDirWindows(
440 result_buf.shrinkAndFree(0);440 result_buf.shrinkAndFree(0);
441 try result_buf.print("{s}\\Lib\\{s}\\ucrt\\{s}", .{ install.path, install.version, arch_sub_dir });441 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) {
444 error.FileNotFound,444 error.FileNotFound,
445 error.NotDir,445 error.NotDir,
446 error.NoDevice,446 error.NoDevice,
...@@ -508,7 +508,7 @@ fn findNativeKernel32LibDir(...@@ -508,7 +508,7 @@ fn findNativeKernel32LibDir(
508 result_buf.shrinkAndFree(0);508 result_buf.shrinkAndFree(0);
509 try result_buf.print("{s}\\Lib\\{s}\\um\\{s}", .{ install.path, install.version, arch_sub_dir });509 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) {
512 error.FileNotFound,512 error.FileNotFound,
513 error.NotDir,513 error.NotDir,
514 error.NoDevice,514 error.NoDevice,
...@@ -544,7 +544,7 @@ fn findNativeMsvcIncludeDir(...@@ -544,7 +544,7 @@ fn findNativeMsvcIncludeDir(
544 const dir_path = try fs.path.join(allocator, &[_][]const u8{ up2, "include" });544 const dir_path = try fs.path.join(allocator, &[_][]const u8{ up2, "include" });
545 errdefer allocator.free(dir_path);545 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) {
548 error.FileNotFound,548 error.FileNotFound,
549 error.NotDir,549 error.NotDir,
550 error.NoDevice,550 error.NoDevice,
lib/std/zig/WindowsSdk.zig+1-1
...@@ -828,7 +828,7 @@ const MsvcLibDir = struct {...@@ -828,7 +828,7 @@ const MsvcLibDir = struct {
828828
829 try lib_dir_buf.appendSlice("VC\\Auxiliary\\Build\\Microsoft.VCToolsVersion.default.txt");829 try lib_dir_buf.appendSlice("VC\\Auxiliary\\Build\\Microsoft.VCToolsVersion.default.txt");
830 var default_tools_version_buf: [512]u8 = undefined;830 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 {
832 return error.PathNotFound;832 return error.PathNotFound;
833 };833 };
834 var tokenizer = std.mem.tokenizeAny(u8, default_tools_version_contents, " \r\n");834 var tokenizer = std.mem.tokenizeAny(u8, default_tools_version_contents, " \r\n");
lib/std/zig/system.zig+4-2
...@@ -1,11 +1,12 @@...@@ -1,11 +1,12 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const native_endian = builtin.cpu.arch.endian();
3
2const std = @import("../std.zig");4const std = @import("../std.zig");
3const mem = std.mem;5const mem = std.mem;
4const elf = std.elf;6const elf = std.elf;
5const fs = std.fs;7const fs = std.fs;
6const assert = std.debug.assert;8const assert = std.debug.assert;
7const Target = std.Target;9const Target = std.Target;
8const native_endian = builtin.cpu.arch.endian();
9const posix = std.posix;10const posix = std.posix;
10const Io = std.Io;11const Io = std.Io;
1112
...@@ -69,7 +70,7 @@ pub fn getExternalExecutor(...@@ -69,7 +70,7 @@ pub fn getExternalExecutor(
69 if (os_match and cpu_ok) native: {70 if (os_match and cpu_ok) native: {
70 if (options.link_libc) {71 if (options.link_libc) {
71 if (candidate.dynamic_linker.get()) |candidate_dl| {72 if (candidate.dynamic_linker.get()) |candidate_dl| {
72 fs.cwd().access(candidate_dl, .{}) catch {73 Io.Dir.cwd().access(candidate_dl, .{}) catch {
73 bad_result = .{ .bad_dl = candidate_dl };74 bad_result = .{ .bad_dl = candidate_dl };
74 break :native;75 break :native;
75 };76 };
...@@ -710,6 +711,7 @@ fn abiAndDynamicLinkerFromFile(...@@ -710,6 +711,7 @@ fn abiAndDynamicLinkerFromFile(
710 error.SystemResources,711 error.SystemResources,
711 error.FileSystem,712 error.FileSystem,
712 error.SymLinkLoop,713 error.SymLinkLoop,
714 error.Canceled,
713 error.Unexpected,715 error.Unexpected,
714 => |e| return e,716 => |e| return e,
715 };717 };
lib/std/zig/system/darwin/macos.zig+4-3
...@@ -1,9 +1,10 @@...@@ -1,9 +1,10 @@
1const std = @import("std");
2const builtin = @import("builtin");1const builtin = @import("builtin");
2
3const std = @import("std");
4const Io = std.Io;
3const assert = std.debug.assert;5const assert = std.debug.assert;
4const mem = std.mem;6const mem = std.mem;
5const testing = std.testing;7const testing = std.testing;
6
7const Target = std.Target;8const Target = std.Target;
89
9/// Detect macOS version.10/// Detect macOS version.
...@@ -54,7 +55,7 @@ pub fn detect(target_os: *Target.Os) !void {...@@ -54,7 +55,7 @@ pub fn detect(target_os: *Target.Os) !void {
54 // approx. 4 times historical file size55 // approx. 4 times historical file size
55 var buf: [2048]u8 = undefined;56 var buf: [2048]u8 = undefined;
5657
57 if (std.fs.cwd().readFile(path, &buf)) |bytes| {58 if (Io.Dir.cwd().readFile(path, &buf)) |bytes| {
58 if (parseSystemVersion(bytes)) |ver| {59 if (parseSystemVersion(bytes)) |ver| {
59 // never return non-canonical `10.(16+)`60 // never return non-canonical `10.(16+)`
60 if (!(ver.major == 10 and ver.minor >= 16)) {61 if (!(ver.major == 10 and ver.minor >= 16)) {
lib/std/zip.zig+2-2
...@@ -564,9 +564,9 @@ pub const Iterator = struct {...@@ -564,9 +564,9 @@ pub const Iterator = struct {
564 defer parent_dir.close(io);564 defer parent_dir.close(io);
565565
566 const basename = std.fs.path.basename(filename);566 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 });
568 }568 }
569 break :blk try dest.createFile(filename, .{ .exclusive = true });569 break :blk try dest.createFile(io, filename, .{ .exclusive = true });
570 };570 };
571 defer out_file.close(io);571 defer out_file.close(io);
572 var out_file_buffer: [1024]u8 = undefined;572 var out_file_buffer: [1024]u8 = undefined;
src/Compilation.zig+10-10
...@@ -450,7 +450,7 @@ pub const Path = struct {...@@ -450,7 +450,7 @@ pub const Path = struct {
450 const dir = switch (p.root) {450 const dir = switch (p.root) {
451 .none => {451 .none => {
452 const cwd_sub_path = absToCwdRelative(p.sub_path, dirs.cwd);452 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 };
454 },454 },
455 .zig_lib => dirs.zig_lib.handle,455 .zig_lib => dirs.zig_lib.handle,
456 .global_cache => dirs.global_cache.handle,456 .global_cache => dirs.global_cache.handle,
...@@ -723,7 +723,7 @@ pub const Directories = struct {...@@ -723,7 +723,7 @@ pub const Directories = struct {
723723
724 pub fn deinit(dirs: *Directories, io: Io) void {724 pub fn deinit(dirs: *Directories, io: Io) void {
725 // The local and global caches could be the same.725 // 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
728 dirs.global_cache.handle.close(io);728 dirs.global_cache.handle.close(io);
729 if (close_local) dirs.local_cache.handle.close(io);729 if (close_local) dirs.local_cache.handle.close(io);
...@@ -814,7 +814,7 @@ pub const Directories = struct {...@@ -814,7 +814,7 @@ pub const Directories = struct {
814 return .{814 return .{
815 .path = if (std.mem.eql(u8, name, ".")) null else name,815 .path = if (std.mem.eql(u8, name, ".")) null else name,
816 .handle = .{816 .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}),
818 },818 },
819 };819 };
820 }820 }
...@@ -824,8 +824,8 @@ pub const Directories = struct {...@@ -824,8 +824,8 @@ pub const Directories = struct {
824 };824 };
825 const nonempty_path = if (path.len == 0) "." else path;825 const nonempty_path = if (path.len == 0) "." else path;
826 const handle_or_err = switch (thing) {826 const handle_or_err = switch (thing) {
827 .@"zig lib" => fs.cwd().openDir(nonempty_path, .{}),827 .@"zig lib" => Io.Dir.cwd().openDir(nonempty_path, .{}),
828 .@"global cache", .@"local cache" => fs.cwd().makeOpenPath(nonempty_path, .{}),828 .@"global cache", .@"local cache" => Io.Dir.cwd().makeOpenPath(nonempty_path, .{}),
829 };829 };
830 return .{830 return .{
831 .path = if (path.len == 0) null else path,831 .path = if (path.len == 0) null else path,
...@@ -1104,7 +1104,7 @@ pub const CObject = struct {...@@ -1104,7 +1104,7 @@ pub const CObject = struct {
1104 const source_line = source_line: {1104 const source_line = source_line: {
1105 if (diag.src_loc.offset == 0 or diag.src_loc.column == 0) break :source_line 0;1105 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;
1108 defer file.close(io);1108 defer file.close(io);
1109 var buffer: [1024]u8 = undefined;1109 var buffer: [1024]u8 = undefined;
1110 var file_reader = file.reader(io, &buffer);1110 var file_reader = file.reader(io, &buffer);
...@@ -1179,7 +1179,7 @@ pub const CObject = struct {...@@ -1179,7 +1179,7 @@ pub const CObject = struct {
1179 };1179 };
11801180
1181 var buffer: [1024]u8 = undefined;1181 var buffer: [1024]u8 = undefined;
1182 const file = try fs.cwd().openFile(io, path, .{});1182 const file = try Io.Dir.cwd().openFile(io, path, .{});
1183 defer file.close(io);1183 defer file.close(io);
1184 var file_reader = file.reader(io, &buffer);1184 var file_reader = file.reader(io, &buffer);
1185 var bc = std.zig.llvm.BitcodeReader.init(gpa, .{ .reader = &file_reader.interface });1185 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,...@@ -2109,7 +2109,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
2109 },2109 },
2110 };2110 };
2111 // These correspond to std.zig.Server.Message.PathPrefix.2111 // 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() });
2113 cache.addPrefix(options.dirs.zig_lib);2113 cache.addPrefix(options.dirs.zig_lib);
2114 cache.addPrefix(options.dirs.local_cache);2114 cache.addPrefix(options.dirs.local_cache);
2115 cache.addPrefix(options.dirs.global_cache);2115 cache.addPrefix(options.dirs.global_cache);
...@@ -5220,7 +5220,7 @@ fn createDepFile(...@@ -5220,7 +5220,7 @@ fn createDepFile(
5220 binfile: Cache.Path,5220 binfile: Cache.Path,
5221) anyerror!void {5221) anyerror!void {
5222 var buf: [4096]u8 = undefined;5222 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 });
5224 defer af.deinit();5224 defer af.deinit();
52255225
5226 comp.writeDepFile(binfile, &af.file_writer.interface) catch return af.file_writer.err.?;5226 comp.writeDepFile(binfile, &af.file_writer.interface) catch return af.file_writer.err.?;
...@@ -5284,7 +5284,7 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {...@@ -5284,7 +5284,7 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void {
5284 };5284 };
5285 }5285 }
52865286
5287 var tar_file = out_dir.createFile("sources.tar", .{}) catch |err| {5287 var tar_file = out_dir.createFile(io, "sources.tar", .{}) catch |err| {
5288 return comp.lockAndSetMiscFailure(5288 return comp.lockAndSetMiscFailure(
5289 .docs_copy,5289 .docs_copy,
5290 "unable to create '{f}/sources.tar': {s}",5290 "unable to create '{f}/sources.tar': {s}",
src/Package/Fetch.zig+6-6
...@@ -383,14 +383,14 @@ pub fn run(f: *Fetch) RunError!void {...@@ -383,14 +383,14 @@ pub fn run(f: *Fetch) RunError!void {
383 },383 },
384 .remote => |remote| remote,384 .remote => |remote| remote,
385 .path_or_url => |path_or_url| {385 .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| {
387 var resource: Resource = .{ .dir = dir };387 var resource: Resource = .{ .dir = dir };
388 return f.runResource(path_or_url, &resource, null);388 return f.runResource(path_or_url, &resource, null);
389 } else |dir_err| {389 } else |dir_err| {
390 var server_header_buffer: [init_resource_buffer_size]u8 = undefined;390 var server_header_buffer: [init_resource_buffer_size]u8 = undefined;
391391
392 const file_err = if (dir_err == error.NotDir) e: {392 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| {
394 var resource: Resource = .{ .file = file.reader(io, &server_header_buffer) };394 var resource: Resource = .{ .file = file.reader(io, &server_header_buffer) };
395 return f.runResource(path_or_url, &resource, null);395 return f.runResource(path_or_url, &resource, null);
396 } else |err| break :e err;396 } else |err| break :e err;
...@@ -1303,7 +1303,7 @@ fn unzip(...@@ -1303,7 +1303,7 @@ fn unzip(
1303 const random_integer = std.crypto.random.int(u64);1303 const random_integer = std.crypto.random.int(u64);
1304 zip_path[prefix.len..][0..random_len].* = std.fmt.hex(random_integer);1304 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, .{
1307 .exclusive = true,1307 .exclusive = true,
1308 .read = true,1308 .read = true,
1309 }) catch |err| switch (err) {1309 }) catch |err| switch (err) {
...@@ -1365,7 +1365,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U...@@ -1365,7 +1365,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
1365 {1365 {
1366 var pack_dir = try out_dir.makeOpenPath(".git", .{});1366 var pack_dir = try out_dir.makeOpenPath(".git", .{});
1367 defer pack_dir.close(io);1367 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 });
1369 defer pack_file.close(io);1369 defer pack_file.close(io);
1370 var pack_file_buffer: [4096]u8 = undefined;1370 var pack_file_buffer: [4096]u8 = undefined;
1371 var pack_file_reader = b: {1371 var pack_file_reader = b: {
...@@ -1376,7 +1376,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U...@@ -1376,7 +1376,7 @@ fn unpackGitPack(f: *Fetch, out_dir: Io.Dir, resource: *Resource.Git) anyerror!U
1376 break :b pack_file_writer.moveToReader(io);1376 break :b pack_file_writer.moveToReader(io);
1377 };1377 };
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 });
1380 defer index_file.close(io);1380 defer index_file.close(io);
1381 var index_file_buffer: [2000]u8 = undefined;1381 var index_file_buffer: [2000]u8 = undefined;
1382 var index_file_writer = index_file.writer(&index_file_buffer);1382 var index_file_writer = index_file.writer(&index_file_buffer);
...@@ -2235,7 +2235,7 @@ test "set executable bit based on file content" {...@@ -2235,7 +2235,7 @@ test "set executable bit based on file content" {
2235fn saveEmbedFile(io: Io, comptime tarball_name: []const u8, dir: Io.Dir) !void {2235fn saveEmbedFile(io: Io, comptime tarball_name: []const u8, dir: Io.Dir) !void {
2236 //const tarball_name = "duplicate_paths_excluded.tar.gz";2236 //const tarball_name = "duplicate_paths_excluded.tar.gz";
2237 const tarball_content = @embedFile("Fetch/testdata/" ++ tarball_name);2237 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, .{});
2239 defer tmp_file.close(io);2239 defer tmp_file.close(io);
2240 try tmp_file.writeAll(tarball_content);2240 try tmp_file.writeAll(tarball_content);
2241}2241}
src/Package/Fetch/git.zig+6-6
...@@ -264,7 +264,7 @@ pub const Repository = struct {...@@ -264,7 +264,7 @@ pub const Repository = struct {
264 try repository.odb.seekOid(entry.oid);264 try repository.odb.seekOid(entry.oid);
265 const file_object = try repository.odb.readObject();265 const file_object = try repository.odb.readObject();
266 if (file_object.type != .blob) return error.InvalidFile;266 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| {
268 const file_name = try std.fs.path.join(diagnostics.allocator, &.{ current_path, entry.name });268 const file_name = try std.fs.path.join(diagnostics.allocator, &.{ current_path, entry.name });
269 errdefer diagnostics.allocator.free(file_name);269 errdefer diagnostics.allocator.free(file_name);
270 try diagnostics.errors.append(diagnostics.allocator, .{ .unable_to_create_file = .{270 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...@@ -1584,14 +1584,14 @@ fn runRepositoryTest(io: Io, comptime format: Oid.Format, head_commit: []const u
15841584
1585 var git_dir = testing.tmpDir(.{});1585 var git_dir = testing.tmpDir(.{});
1586 defer git_dir.cleanup();1586 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 });
1588 defer pack_file.close(io);1588 defer pack_file.close(io);
1589 try pack_file.writeAll(testrepo_pack);1589 try pack_file.writeAll(testrepo_pack);
15901590
1591 var pack_file_buffer: [2000]u8 = undefined;1591 var pack_file_buffer: [2000]u8 = undefined;
1592 var pack_file_reader = pack_file.reader(io, &pack_file_buffer);1592 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 });
1595 defer index_file.close(io);1595 defer index_file.close(io);
1596 var index_file_buffer: [2000]u8 = undefined;1596 var index_file_buffer: [2000]u8 = undefined;
1597 var index_file_writer = index_file.writer(&index_file_buffer);1597 var index_file_writer = index_file.writer(&index_file_buffer);
...@@ -1714,20 +1714,20 @@ pub fn main() !void {...@@ -1714,20 +1714,20 @@ pub fn main() !void {
17141714
1715 const format = std.meta.stringToEnum(Oid.Format, args[1]) orelse return error.InvalidFormat;1715 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], .{});
1718 defer pack_file.close(io);1718 defer pack_file.close(io);
1719 var pack_file_buffer: [4096]u8 = undefined;1719 var pack_file_buffer: [4096]u8 = undefined;
1720 var pack_file_reader = pack_file.reader(io, &pack_file_buffer);1720 var pack_file_reader = pack_file.reader(io, &pack_file_buffer);
17211721
1722 const commit = try Oid.parse(format, args[3]);1722 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], .{});
1724 defer worktree.close(io);1724 defer worktree.close(io);
17251725
1726 var git_dir = try worktree.makeOpenPath(".git", .{});1726 var git_dir = try worktree.makeOpenPath(".git", .{});
1727 defer git_dir.close(io);1727 defer git_dir.close(io);
17281728
1729 std.debug.print("Starting index...\n", .{});1729 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 });
1731 defer index_file.close(io);1731 defer index_file.close(io);
1732 var index_file_buffer: [4096]u8 = undefined;1732 var index_file_buffer: [4096]u8 = undefined;
1733 var index_file_writer = index_file.writer(&index_file_buffer);1733 var index_file_writer = index_file.writer(&index_file_buffer);
src/Zcu/PerThread.zig+2-2
...@@ -170,7 +170,7 @@ pub fn updateFile(...@@ -170,7 +170,7 @@ pub fn updateFile(
170 // version. Likewise if we're working on AstGen and another process asks for170 // version. Likewise if we're working on AstGen and another process asks for
171 // the cached file, they'll get it.171 // the cached file, they'll get it.
172 const cache_file = while (true) {172 const cache_file = while (true) {
173 break zir_dir.createFile(&hex_digest, .{173 break zir_dir.createFile(io, &hex_digest, .{
174 .read = true,174 .read = true,
175 .truncate = false,175 .truncate = false,
176 .lock = lock,176 .lock = lock,
...@@ -196,7 +196,7 @@ pub fn updateFile(...@@ -196,7 +196,7 @@ pub fn updateFile(
196 cache_directory,196 cache_directory,
197 });197 });
198 }198 }
199 break zir_dir.createFile(&hex_digest, .{199 break zir_dir.createFile(io, &hex_digest, .{
200 .read = true,200 .read = true,
201 .truncate = false,201 .truncate = false,
202 .lock = lock,202 .lock = lock,
src/codegen/llvm.zig+10-7
...@@ -1,19 +1,22 @@...@@ -1,19 +1,22 @@
1const std = @import("std");
2const builtin = @import("builtin");1const builtin = @import("builtin");
2
3const std = @import("std");
4const Io = std.Io;
3const assert = std.debug.assert;5const assert = std.debug.assert;
4const Allocator = std.mem.Allocator;6const Allocator = std.mem.Allocator;
5const log = std.log.scoped(.codegen);7const log = std.log.scoped(.codegen);
6const math = std.math;8const math = std.math;
7const DW = std.dwarf;9const DW = std.dwarf;
8
9const Builder = std.zig.llvm.Builder;10const Builder = std.zig.llvm.Builder;
11
12const build_options = @import("build_options");
10const llvm = if (build_options.have_llvm)13const llvm = if (build_options.have_llvm)
11 @import("llvm/bindings.zig")14 @import("llvm/bindings.zig")
12else15else
13 @compileError("LLVM unavailable");16 @compileError("LLVM unavailable");
17
14const link = @import("../link.zig");18const link = @import("../link.zig");
15const Compilation = @import("../Compilation.zig");19const Compilation = @import("../Compilation.zig");
16const build_options = @import("build_options");
17const Zcu = @import("../Zcu.zig");20const Zcu = @import("../Zcu.zig");
18const InternPool = @import("../InternPool.zig");21const InternPool = @import("../InternPool.zig");
19const Package = @import("../Package.zig");22const Package = @import("../Package.zig");
...@@ -964,7 +967,7 @@ pub const Object = struct {...@@ -964,7 +967,7 @@ pub const Object = struct {
964 if (std.mem.eql(u8, path, "-")) {967 if (std.mem.eql(u8, path, "-")) {
965 o.builder.dump();968 o.builder.dump();
966 } else {969 } else {
967 o.builder.printToFilePath(std.fs.cwd(), path) catch |err| {970 o.builder.printToFilePath(Io.Dir.cwd(), path) catch |err| {
968 log.err("failed printing LLVM module to \"{s}\": {s}", .{ path, @errorName(err) });971 log.err("failed printing LLVM module to \"{s}\": {s}", .{ path, @errorName(err) });
969 };972 };
970 }973 }
...@@ -978,7 +981,7 @@ pub const Object = struct {...@@ -978,7 +981,7 @@ pub const Object = struct {
978 o.builder.clearAndFree();981 o.builder.clearAndFree();
979982
980 if (options.pre_bc_path) |path| {983 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|
982 return diags.fail("failed to create '{s}': {s}", .{ path, @errorName(err) });985 return diags.fail("failed to create '{s}': {s}", .{ path, @errorName(err) });
983 defer file.close(io);986 defer file.close(io);
984987
...@@ -991,7 +994,7 @@ pub const Object = struct {...@@ -991,7 +994,7 @@ pub const Object = struct {
991 options.post_ir_path == null and options.post_bc_path == null) return;994 options.post_ir_path == null and options.post_bc_path == null) return;
992995
993 if (options.post_bc_path) |path| {996 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|
995 return diags.fail("failed to create '{s}': {s}", .{ path, @errorName(err) });998 return diags.fail("failed to create '{s}': {s}", .{ path, @errorName(err) });
996 defer file.close(io);999 defer file.close(io);
9971000
...@@ -2711,7 +2714,7 @@ pub const Object = struct {...@@ -2711,7 +2714,7 @@ pub const Object = struct {
2711 }2714 }
27122715
2713 fn allocTypeName(o: *Object, pt: Zcu.PerThread, ty: Type) Allocator.Error![:0]const u8 {2716 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);
2715 defer aw.deinit();2718 defer aw.deinit();
2716 ty.print(&aw.writer, pt, null) catch |err| switch (err) {2719 ty.print(&aw.writer, pt, null) catch |err| switch (err) {
2717 error.WriteFailed => return error.OutOfMemory,2720 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) !...@@ -182,11 +182,11 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
182 // Mark any excluded files/directories as already seen,182 // Mark any excluded files/directories as already seen,
183 // so that they are skipped later during actual processing183 // so that they are skipped later during actual processing
184 for (excluded_files.items) |file_path| {184 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) {
186 error.FileNotFound => continue,186 error.FileNotFound => continue,
187 // On Windows, statFile does not work for directories187 // On Windows, statFile does not work for directories
188 error.IsDir => dir: {188 error.IsDir => dir: {
189 var dir = try fs.cwd().openDir(file_path, .{});189 var dir = try Io.Dir.cwd().openDir(file_path, .{});
190 defer dir.close(io);190 defer dir.close(io);
191 break :dir try dir.stat();191 break :dir try dir.stat();
192 },192 },
...@@ -196,7 +196,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !...@@ -196,7 +196,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
196 }196 }
197197
198 for (input_files.items) |file_path| {198 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);
200 }200 }
201 try fmt.stdout_writer.interface.flush();201 try fmt.stdout_writer.interface.flush();
202 if (fmt.any_error) {202 if (fmt.any_error) {
src/introspect.zig+2-2
...@@ -82,7 +82,7 @@ pub fn findZigLibDirFromSelfExe(...@@ -82,7 +82,7 @@ pub fn findZigLibDirFromSelfExe(
82 cwd_path: []const u8,82 cwd_path: []const u8,
83 self_exe_path: []const u8,83 self_exe_path: []const u8,
84) error{ OutOfMemory, FileNotFound }!Cache.Directory {84) error{ OutOfMemory, FileNotFound }!Cache.Directory {
85 const cwd = fs.cwd();85 const cwd = Io.Dir.cwd();
86 var cur_path: []const u8 = self_exe_path;86 var cur_path: []const u8 = self_exe_path;
87 while (fs.path.dirname(cur_path)) |dirname| : (cur_path = dirname) {87 while (fs.path.dirname(cur_path)) |dirname| : (cur_path = dirname) {
88 var base_dir = cwd.openDir(dirname, .{}) catch continue;88 var base_dir = cwd.openDir(dirname, .{}) catch continue;
...@@ -206,7 +206,7 @@ pub fn resolveSuitableLocalCacheDir(arena: Allocator, cwd: []const u8) Allocator...@@ -206,7 +206,7 @@ pub fn resolveSuitableLocalCacheDir(arena: Allocator, cwd: []const u8) Allocator
206 var cur_dir = cwd;206 var cur_dir = cwd;
207 while (true) {207 while (true) {
208 const joined = try fs.path.join(arena, &.{ cur_dir, Package.build_zig_basename });208 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, .{})) |_| {
210 return try fs.path.join(arena, &.{ cur_dir, default_local_zig_cache_basename });210 return try fs.path.join(arena, &.{ cur_dir, default_local_zig_cache_basename });
211 } else |err| switch (err) {211 } else |err| switch (err) {
212 error.FileNotFound => {212 error.FileNotFound => {
src/libs/freebsd.zig+6-6
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const Allocator = std.mem.Allocator;3const Allocator = std.mem.Allocator;
3const mem = std.mem;4const mem = std.mem;
4const log = std.log;5const log = std.log;
5const fs = std.fs;6const path = std.Io.Dir.path;
6const path = fs.path;
7const assert = std.debug.assert;7const assert = std.debug.assert;
8const Version = std.SemanticVersion;8const Version = std.SemanticVersion;
9const Path = std.Build.Cache.Path;9const Path = std.Build.Cache.Path;
...@@ -446,7 +446,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -446,7 +446,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
446 .io = io,446 .io = io,
447 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),447 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
448 };448 };
449 cache.addPrefix(.{ .path = null, .handle = fs.cwd() });449 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
450 cache.addPrefix(comp.dirs.zig_lib);450 cache.addPrefix(comp.dirs.zig_lib);
451 cache.addPrefix(comp.dirs.global_cache);451 cache.addPrefix(comp.dirs.global_cache);
452 defer cache.manifest_dir.close(io);452 defer cache.manifest_dir.close(io);
...@@ -468,7 +468,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -468,7 +468,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
468 .lock = man.toOwnedLock(),468 .lock = man.toOwnedLock(),
469 .dir_path = .{469 .dir_path = .{
470 .root_dir = comp.dirs.global_cache,470 .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),
472 },472 },
473 });473 });
474 }474 }
...@@ -986,7 +986,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -986,7 +986,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
986 .lock = man.toOwnedLock(),986 .lock = man.toOwnedLock(),
987 .dir_path = .{987 .dir_path = .{
988 .root_dir = comp.dirs.global_cache,988 .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),
990 },990 },
991 });991 });
992}992}
...@@ -1014,7 +1014,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) std.Io.C...@@ -1014,7 +1014,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) std.Io.C
1014 const so_path: Path = .{1014 const so_path: Path = .{
1015 .root_dir = so_files.dir_path.root_dir,1015 .root_dir = so_files.dir_path.root_dir,
1016 .sub_path = std.fmt.allocPrint(comp.arena, "{s}{c}lib{s}.so.{d}", .{1016 .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),
1018 }) catch return comp.setAllocFailure(),1018 }) catch return comp.setAllocFailure(),
1019 };1019 };
1020 task_buffer[task_buffer_i] = .{ .load_dso = so_path };1020 task_buffer[task_buffer_i] = .{ .load_dso = so_path };
src/libs/glibc.zig+8-8
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const Allocator = std.mem.Allocator;3const Allocator = std.mem.Allocator;
3const mem = std.mem;4const mem = std.mem;
4const log = std.log;5const log = std.log;
5const fs = std.fs;6const path = std.Io.Dir.path;
6const path = fs.path;
7const assert = std.debug.assert;7const assert = std.debug.assert;
8const Version = std.SemanticVersion;8const Version = std.SemanticVersion;
9const Path = std.Build.Cache.Path;9const Path = std.Build.Cache.Path;
...@@ -681,7 +681,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -681,7 +681,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
681 .io = io,681 .io = io,
682 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),682 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
683 };683 };
684 cache.addPrefix(.{ .path = null, .handle = fs.cwd() });684 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
685 cache.addPrefix(comp.dirs.zig_lib);685 cache.addPrefix(comp.dirs.zig_lib);
686 cache.addPrefix(comp.dirs.global_cache);686 cache.addPrefix(comp.dirs.global_cache);
687 defer cache.manifest_dir.close(io);687 defer cache.manifest_dir.close(io);
...@@ -703,7 +703,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -703,7 +703,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
703 .lock = man.toOwnedLock(),703 .lock = man.toOwnedLock(),
704 .dir_path = .{704 .dir_path = .{
705 .root_dir = comp.dirs.global_cache,705 .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),
707 },707 },
708 });708 });
709 }709 }
...@@ -775,7 +775,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -775,7 +775,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
775 try stubs_asm.appendSlice(".text\n");775 try stubs_asm.appendSlice(".text\n");
776776
777 var sym_i: usize = 0;777 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);
779 var opt_symbol_name: ?[]const u8 = null;779 var opt_symbol_name: ?[]const u8 = null;
780 var versions_buffer: [32]u8 = undefined;780 var versions_buffer: [32]u8 = undefined;
781 var versions_len: usize = undefined;781 var versions_len: usize = undefined;
...@@ -796,7 +796,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -796,7 +796,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
796 // twice, which causes a "duplicate symbol" assembler error.796 // twice, which causes a "duplicate symbol" assembler error.
797 var versions_written = std.AutoArrayHashMap(Version, void).init(arena);797 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
801 const fn_inclusions_len = try inc_reader.takeInt(u16, .little);801 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...@@ -1130,7 +1130,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
1130 .lock = man.toOwnedLock(),1130 .lock = man.toOwnedLock(),
1131 .dir_path = .{1131 .dir_path = .{
1132 .root_dir = comp.dirs.global_cache,1132 .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),
1134 },1134 },
1135 });1135 });
1136}1136}
...@@ -1156,7 +1156,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) std.Io.C...@@ -1156,7 +1156,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) std.Io.C
1156 const so_path: Path = .{1156 const so_path: Path = .{
1157 .root_dir = so_files.dir_path.root_dir,1157 .root_dir = so_files.dir_path.root_dir,
1158 .sub_path = std.fmt.allocPrint(comp.arena, "{s}{c}lib{s}.so.{d}", .{1158 .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,
1160 }) catch return comp.setAllocFailure(),1160 }) catch return comp.setAllocFailure(),
1161 };1161 };
1162 task_buffer[task_buffer_i] = .{ .load_dso = so_path };1162 task_buffer[task_buffer_i] = .{ .load_dso = so_path };
src/libs/mingw.zig+9-8
...@@ -1,7 +1,8 @@...@@ -1,7 +1,8 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const Allocator = std.mem.Allocator;3const Allocator = std.mem.Allocator;
3const mem = std.mem;4const mem = std.mem;
4const path = std.fs.path;5const path = std.Io.Dir.path;
5const assert = std.debug.assert;6const assert = std.debug.assert;
6const log = std.log.scoped(.mingw);7const log = std.log.scoped(.mingw);
78
...@@ -259,7 +260,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -259,7 +260,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
259 .io = io,260 .io = io,
260 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),261 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
261 };262 };
262 cache.addPrefix(.{ .path = null, .handle = std.fs.cwd() });263 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
263 cache.addPrefix(comp.dirs.zig_lib);264 cache.addPrefix(comp.dirs.zig_lib);
264 cache.addPrefix(comp.dirs.global_cache);265 cache.addPrefix(comp.dirs.global_cache);
265 defer cache.manifest_dir.close(io);266 defer cache.manifest_dir.close(io);
...@@ -304,7 +305,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -304,7 +305,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
304 .output = .{ .to_list = .{ .arena = .init(gpa) } },305 .output = .{ .to_list = .{ .arena = .init(gpa) } },
305 };306 };
306 defer diagnostics.deinit();307 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());
308 defer aro_comp.deinit();309 defer aro_comp.deinit();
309310
310 aro_comp.target = .fromZigTarget(target.*);311 aro_comp.target = .fromZigTarget(target.*);
...@@ -343,7 +344,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -343,7 +344,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
343 }344 }
344345
345 const members = members: {346 const members = members: {
346 var aw: std.Io.Writer.Allocating = .init(gpa);347 var aw: Io.Writer.Allocating = .init(gpa);
347 errdefer aw.deinit();348 errdefer aw.deinit();
348 try pp.prettyPrintTokens(&aw.writer, .result_only);349 try pp.prettyPrintTokens(&aw.writer, .result_only);
349350
...@@ -376,7 +377,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -376,7 +377,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
376 errdefer gpa.free(lib_final_path);377 errdefer gpa.free(lib_final_path);
377378
378 {379 {
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 });
380 defer lib_final_file.close(io);381 defer lib_final_file.close(io);
381 var buffer: [1024]u8 = undefined;382 var buffer: [1024]u8 = undefined;
382 var file_writer = lib_final_file.writer(&buffer);383 var file_writer = lib_final_file.writer(&buffer);
...@@ -442,7 +443,7 @@ fn findDef(...@@ -442,7 +443,7 @@ fn findDef(
442 } else {443 } else {
443 try override_path.print(fmt_path, .{ lib_path, lib_name });444 try override_path.print(fmt_path, .{ lib_path, lib_name });
444 }445 }
445 if (std.fs.cwd().access(override_path.items, .{})) |_| {446 if (Io.Dir.cwd().access(override_path.items, .{})) |_| {
446 return override_path.toOwnedSlice();447 return override_path.toOwnedSlice();
447 } else |err| switch (err) {448 } else |err| switch (err) {
448 error.FileNotFound => {},449 error.FileNotFound => {},
...@@ -459,7 +460,7 @@ fn findDef(...@@ -459,7 +460,7 @@ fn findDef(
459 } else {460 } else {
460 try override_path.print(fmt_path, .{lib_name});461 try override_path.print(fmt_path, .{lib_name});
461 }462 }
462 if (std.fs.cwd().access(override_path.items, .{})) |_| {463 if (Io.Dir.cwd().access(override_path.items, .{})) |_| {
463 return override_path.toOwnedSlice();464 return override_path.toOwnedSlice();
464 } else |err| switch (err) {465 } else |err| switch (err) {
465 error.FileNotFound => {},466 error.FileNotFound => {},
...@@ -476,7 +477,7 @@ fn findDef(...@@ -476,7 +477,7 @@ fn findDef(
476 } else {477 } else {
477 try override_path.print(fmt_path, .{lib_name});478 try override_path.print(fmt_path, .{lib_name});
478 }479 }
479 if (std.fs.cwd().access(override_path.items, .{})) |_| {480 if (Io.Dir.cwd().access(override_path.items, .{})) |_| {
480 return override_path.toOwnedSlice();481 return override_path.toOwnedSlice();
481 } else |err| switch (err) {482 } else |err| switch (err) {
482 error.FileNotFound => {},483 error.FileNotFound => {},
src/libs/netbsd.zig+6-6
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1const std = @import("std");1const std = @import("std");
2const Io = std.Io;
2const Allocator = std.mem.Allocator;3const Allocator = std.mem.Allocator;
3const mem = std.mem;4const mem = std.mem;
4const log = std.log;5const log = std.log;
5const fs = std.fs;6const path = std.Io.Dir.path;
6const path = fs.path;
7const assert = std.debug.assert;7const assert = std.debug.assert;
8const Version = std.SemanticVersion;8const Version = std.SemanticVersion;
9const Path = std.Build.Cache.Path;9const Path = std.Build.Cache.Path;
...@@ -387,7 +387,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -387,7 +387,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
387 .io = io,387 .io = io,
388 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),388 .manifest_dir = try comp.dirs.global_cache.handle.makeOpenPath("h", .{}),
389 };389 };
390 cache.addPrefix(.{ .path = null, .handle = fs.cwd() });390 cache.addPrefix(.{ .path = null, .handle = Io.Dir.cwd() });
391 cache.addPrefix(comp.dirs.zig_lib);391 cache.addPrefix(comp.dirs.zig_lib);
392 cache.addPrefix(comp.dirs.global_cache);392 cache.addPrefix(comp.dirs.global_cache);
393 defer cache.manifest_dir.close(io);393 defer cache.manifest_dir.close(io);
...@@ -409,7 +409,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -409,7 +409,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
409 .lock = man.toOwnedLock(),409 .lock = man.toOwnedLock(),
410 .dir_path = .{410 .dir_path = .{
411 .root_dir = comp.dirs.global_cache,411 .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),
413 },413 },
414 });414 });
415 }415 }
...@@ -640,7 +640,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye...@@ -640,7 +640,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
640 .lock = man.toOwnedLock(),640 .lock = man.toOwnedLock(),
641 .dir_path = .{641 .dir_path = .{
642 .root_dir = comp.dirs.global_cache,642 .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),
644 },644 },
645 });645 });
646}646}
...@@ -661,7 +661,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) std.Io.C...@@ -661,7 +661,7 @@ fn queueSharedObjects(comp: *Compilation, so_files: BuiltSharedObjects) std.Io.C
661 const so_path: Path = .{661 const so_path: Path = .{
662 .root_dir = so_files.dir_path.root_dir,662 .root_dir = so_files.dir_path.root_dir,
663 .sub_path = std.fmt.allocPrint(comp.arena, "{s}{c}lib{s}.so.{d}", .{663 .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,
665 }) catch return comp.setAllocFailure(),665 }) catch return comp.setAllocFailure(),
666 };666 };
667 task_buffer[task_buffer_i] = .{ .load_dso = so_path };667 task_buffer[task_buffer_i] = .{ .load_dso = so_path };
src/link/C.zig+2-2
...@@ -136,7 +136,7 @@ pub fn createEmpty(...@@ -136,7 +136,7 @@ pub fn createEmpty(
136 assert(!use_lld);136 assert(!use_lld);
137 assert(!use_llvm);137 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, .{
140 // Truncation is done on `flush`.140 // Truncation is done on `flush`.
141 .truncate = false,141 .truncate = false,
142 });142 });
...@@ -792,7 +792,7 @@ pub fn flushEmitH(zcu: *Zcu) !void {...@@ -792,7 +792,7 @@ pub fn flushEmitH(zcu: *Zcu) !void {
792 }792 }
793793
794 const directory = emit_h.loc.directory orelse zcu.comp.local_cache_directory;794 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, .{
796 // We set the end position explicitly below; by not truncating the file, we possibly796 // We set the end position explicitly below; by not truncating the file, we possibly
797 // make it easier on the file system by doing 1 reallocation instead of two.797 // make it easier on the file system by doing 1 reallocation instead of two.
798 .truncate = false,798 .truncate = false,
src/link/Coff.zig+4-2
...@@ -631,12 +631,14 @@ fn create(...@@ -631,12 +631,14 @@ fn create(
631 else => return error.UnsupportedCOFFArchitecture,631 else => return error.UnsupportedCOFFArchitecture,
632 };632 };
633633
634 const io = comp.io;
635
634 const coff = try arena.create(Coff);636 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, .{
636 .read = true,638 .read = true,
637 .mode = link.File.determineMode(comp.config.output_mode, comp.config.link_mode),639 .mode = link.File.determineMode(comp.config.output_mode, comp.config.link_mode),
638 });640 });
639 errdefer file.close(comp.io);641 errdefer file.close(io);
640 coff.* = .{642 coff.* = .{
641 .base = .{643 .base = .{
642 .tag = .coff2,644 .tag = .coff2,
src/link/Elf.zig+3-1
...@@ -313,9 +313,11 @@ pub fn createEmpty(...@@ -313,9 +313,11 @@ pub fn createEmpty(
313 const is_obj = output_mode == .Obj;313 const is_obj = output_mode == .Obj;
314 const is_obj_or_ar = is_obj or (output_mode == .Lib and link_mode == .static);314 const is_obj_or_ar = is_obj or (output_mode == .Lib and link_mode == .static);
315315
316 const io = comp.io;
317
316 // What path should this ELF linker code output to?318 // What path should this ELF linker code output to?
317 const sub_path = emit.sub_path;319 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, .{
319 .truncate = true,321 .truncate = true,
320 .read = true,322 .read = true,
321 .mode = link.File.determineMode(output_mode, link_mode),323 .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 {...@@ -1572,7 +1572,7 @@ fn wasmLink(lld: *Lld, arena: Allocator) !void {
1572 // report a nice error here with the file path if it fails instead of1572 // report a nice error here with the file path if it fails instead of
1573 // just returning the error code.1573 // just returning the error code.
1574 // chmod does not interact with umask, so we use a conservative -rwxr--r-- here.1574 // 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) {
1576 error.OperationNotSupported => unreachable, // Not a symlink.1576 error.OperationNotSupported => unreachable, // Not a symlink.
1577 else => |e| return e,1577 else => |e| return e,
1578 };1578 };
...@@ -1624,7 +1624,7 @@ fn spawnLld(comp: *Compilation, arena: Allocator, argv: []const []const u8) !voi...@@ -1624,7 +1624,7 @@ fn spawnLld(comp: *Compilation, arena: Allocator, argv: []const []const u8) !voi
1624 const rand_int = std.crypto.random.int(u64);1624 const rand_int = std.crypto.random.int(u64);
1625 const rsp_path = "tmp" ++ s ++ std.fmt.hex(rand_int) ++ ".rsp";1625 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, .{});
1628 defer comp.dirs.local_cache.handle.deleteFileZ(rsp_path) catch |err|1628 defer comp.dirs.local_cache.handle.deleteFileZ(rsp_path) catch |err|
1629 log.warn("failed to delete response file {s}: {s}", .{ rsp_path, @errorName(err) });1629 log.warn("failed to delete response file {s}: {s}", .{ rsp_path, @errorName(err) });
1630 {1630 {
src/link/MachO.zig+8-6
...@@ -219,7 +219,9 @@ pub fn createEmpty(...@@ -219,7 +219,9 @@ pub fn createEmpty(
219 };219 };
220 errdefer self.base.destroy();220 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, .{
223 .truncate = true,225 .truncate = true,
224 .read = true,226 .read = true,
225 .mode = link.File.determineMode(output_mode, link_mode),227 .mode = link.File.determineMode(output_mode, link_mode),
...@@ -1082,7 +1084,7 @@ fn accessLibPath(...@@ -1082,7 +1084,7 @@ fn accessLibPath(
1082 test_path.clearRetainingCapacity();1084 test_path.clearRetainingCapacity();
1083 try test_path.print("{s}" ++ sep ++ "lib{s}{s}", .{ search_dir, name, ext });1085 try test_path.print("{s}" ++ sep ++ "lib{s}{s}", .{ search_dir, name, ext });
1084 try checked_paths.append(try arena.dupe(u8, test_path.items));1086 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) {
1086 error.FileNotFound => continue,1088 error.FileNotFound => continue,
1087 else => |e| return e,1089 else => |e| return e,
1088 };1090 };
...@@ -1110,7 +1112,7 @@ fn accessFrameworkPath(...@@ -1110,7 +1112,7 @@ fn accessFrameworkPath(
1110 ext,1112 ext,
1111 });1113 });
1112 try checked_paths.append(try arena.dupe(u8, test_path.items));1114 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) {
1114 error.FileNotFound => continue,1116 error.FileNotFound => continue,
1115 else => |e| return e,1117 else => |e| return e,
1116 };1118 };
...@@ -1191,7 +1193,7 @@ fn parseDependentDylibs(self: *MachO) !void {...@@ -1191,7 +1193,7 @@ fn parseDependentDylibs(self: *MachO) !void {
1191 try test_path.print("{s}{s}", .{ path, ext });1193 try test_path.print("{s}{s}", .{ path, ext });
1192 }1194 }
1193 try checked_paths.append(try arena.dupe(u8, test_path.items));1195 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) {
1195 error.FileNotFound => continue,1197 error.FileNotFound => continue,
1196 else => |e| return e,1198 else => |e| return e,
1197 };1199 };
...@@ -3289,7 +3291,7 @@ pub fn reopenDebugInfo(self: *MachO) !void {...@@ -3289,7 +3291,7 @@ pub fn reopenDebugInfo(self: *MachO) !void {
3289 var d_sym_bundle = try self.base.emit.root_dir.handle.makeOpenPath(d_sym_path, .{});3291 var d_sym_bundle = try self.base.emit.root_dir.handle.makeOpenPath(d_sym_path, .{});
3290 defer d_sym_bundle.close(io);3292 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), .{
3293 .truncate = false,3295 .truncate = false,
3294 .read = true,3296 .read = true,
3295 });3297 });
...@@ -4370,7 +4372,7 @@ fn inferSdkVersion(comp: *Compilation, sdk_layout: SdkLayout) ?std.SemanticVersi...@@ -4370,7 +4372,7 @@ fn inferSdkVersion(comp: *Compilation, sdk_layout: SdkLayout) ?std.SemanticVersi
4370// The file/property is also available with vendored libc.4372// The file/property is also available with vendored libc.
4371fn readSdkVersionFromSettings(arena: Allocator, dir: []const u8) ![]const u8 {4373fn readSdkVersionFromSettings(arena: Allocator, dir: []const u8) ![]const u8 {
4372 const sdk_path = try fs.path.join(arena, &.{ dir, "SDKSettings.json" });4374 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)));
4374 const parsed = try std.json.parseFromSlice(std.json.Value, arena, contents, .{});4376 const parsed = try std.json.parseFromSlice(std.json.Value, arena, contents, .{});
4375 if (parsed.value.object.get("MinimalDisplayName")) |ver| return ver.string;4377 if (parsed.value.object.get("MinimalDisplayName")) |ver| return ver.string;
4376 return error.SdkVersionFailure;4378 return error.SdkVersionFailure;
src/link/MachO/CodeSignature.zig+1-1
...@@ -247,7 +247,7 @@ pub fn deinit(self: *CodeSignature, allocator: Allocator) void {...@@ -247,7 +247,7 @@ pub fn deinit(self: *CodeSignature, allocator: Allocator) void {
247}247}
248248
249pub fn addEntitlements(self: *CodeSignature, allocator: Allocator, path: []const u8) !void {249pub 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)));
251 self.entitlements = .{ .inner = inner };251 self.entitlements = .{ .inner = inner };
252}252}
253253
src/link/SpirV.zig+2-1
...@@ -33,6 +33,7 @@ pub fn createEmpty(...@@ -33,6 +33,7 @@ pub fn createEmpty(
33 options: link.File.OpenOptions,33 options: link.File.OpenOptions,
34) !*Linker {34) !*Linker {
35 const gpa = comp.gpa;35 const gpa = comp.gpa;
36 const io = comp.io;
36 const target = &comp.root_mod.resolved_target.result;37 const target = &comp.root_mod.resolved_target.result;
3738
38 assert(!comp.config.use_lld); // Caught by Compilation.Config.resolve39 assert(!comp.config.use_lld); // Caught by Compilation.Config.resolve
...@@ -78,7 +79,7 @@ pub fn createEmpty(...@@ -78,7 +79,7 @@ pub fn createEmpty(
78 };79 };
79 errdefer linker.deinit();80 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, .{
82 .truncate = true,83 .truncate = true,
83 .read = true,84 .read = true,
84 });85 });
src/link/Wasm.zig+3-1
...@@ -2997,7 +2997,9 @@ pub fn createEmpty(...@@ -2997,7 +2997,9 @@ pub fn createEmpty(
2997 .named => |name| (try wasm.internString(name)).toOptional(),2997 .named => |name| (try wasm.internString(name)).toOptional(),
2998 };2998 };
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, .{
3001 .truncate = true,3003 .truncate = true,
3002 .read = true,3004 .read = true,
3003 .mode = if (fs.has_executable_bit)3005 .mode = if (fs.has_executable_bit)
src/main.zig+18-18
...@@ -713,7 +713,7 @@ const Emit = union(enum) {...@@ -713,7 +713,7 @@ const Emit = union(enum) {
713 } else e: {713 } else e: {
714 // If there's a dirname, check that dir exists. This will give a more descriptive error than `Compilation` otherwise would.714 // If there's a dirname, check that dir exists. This will give a more descriptive error than `Compilation` otherwise would.
715 if (fs.path.dirname(path)) |dir_path| {715 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| {
717 fatal("unable to open output directory '{s}': {s}", .{ dir_path, @errorName(err) });717 fatal("unable to open output directory '{s}': {s}", .{ dir_path, @errorName(err) });
718 };718 };
719 dir.close(io);719 dir.close(io);
...@@ -3304,7 +3304,7 @@ fn buildOutputType(...@@ -3304,7 +3304,7 @@ fn buildOutputType(
3304 } else emit: {3304 } else emit: {
3305 // If there's a dirname, check that dir exists. This will give a more descriptive error than `Compilation` otherwise would.3305 // If there's a dirname, check that dir exists. This will give a more descriptive error than `Compilation` otherwise would.
3306 if (fs.path.dirname(path)) |dir_path| {3306 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| {
3308 fatal("unable to open output directory '{s}': {s}", .{ dir_path, @errorName(err) });3308 fatal("unable to open output directory '{s}': {s}", .{ dir_path, @errorName(err) });
3309 };3309 };
3310 dir.close(io);3310 dir.close(io);
...@@ -3389,7 +3389,7 @@ fn buildOutputType(...@@ -3389,7 +3389,7 @@ fn buildOutputType(
3389 // file will not run and this temp file will be leaked. The filename3389 // file will not run and this temp file will be leaked. The filename
3390 // will be a hash of its contents — so multiple invocations of3390 // will be a hash of its contents — so multiple invocations of
3391 // `zig cc -` will result in the same temp file name.3391 // `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, .{});
3393 defer f.close(io);3393 defer f.close(io);
33943394
3395 // Re-using the hasher from Cache, since the functional requirements3395 // 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) !...@@ -4773,7 +4773,7 @@ fn cmdInit(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
4773 var ok_count: usize = 0;4773 var ok_count: usize = 0;
47744774
4775 for (template_paths) |template_path| {4775 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)) |_| {
4777 std.log.info("created {s}", .{template_path});4777 std.log.info("created {s}", .{template_path});
4778 ok_count += 1;4778 ok_count += 1;
4779 } else |err| switch (err) {4779 } else |err| switch (err) {
...@@ -5227,7 +5227,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)...@@ -5227,7 +5227,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
5227 if (system_pkg_dir_path) |p| {5227 if (system_pkg_dir_path) |p| {
5228 job_queue.global_cache = .{5228 job_queue.global_cache = .{
5229 .path = p,5229 .path = p,
5230 .handle = fs.cwd().openDir(p, .{}) catch |err| {5230 .handle = Io.Dir.cwd().openDir(p, .{}) catch |err| {
5231 fatal("unable to open system package directory '{s}': {s}", .{5231 fatal("unable to open system package directory '{s}': {s}", .{
5232 p, @errorName(err),5232 p, @errorName(err),
5233 });5233 });
...@@ -5823,7 +5823,7 @@ const ArgIteratorResponseFile = process.ArgIteratorGeneral(.{ .comments = true,...@@ -5823,7 +5823,7 @@ const ArgIteratorResponseFile = process.ArgIteratorGeneral(.{ .comments = true,
5823/// Initialize the arguments from a Response File. "*.rsp"5823/// Initialize the arguments from a Response File. "*.rsp"
5824fn initArgIteratorResponseFile(allocator: Allocator, resp_file_path: []const u8) !ArgIteratorResponseFile {5824fn initArgIteratorResponseFile(allocator: Allocator, resp_file_path: []const u8) !ArgIteratorResponseFile {
5825 const max_bytes = 10 * 1024 * 1024; // 10 MiB of command line arguments is a reasonable limit5825 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));
5827 errdefer allocator.free(cmd_line);5827 errdefer allocator.free(cmd_line);
58285828
5829 return ArgIteratorResponseFile.initTakeOwnership(allocator, cmd_line);5829 return ArgIteratorResponseFile.initTakeOwnership(allocator, cmd_line);
...@@ -6187,7 +6187,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {...@@ -6187,7 +6187,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
6187 const display_path = zig_source_path orelse "<stdin>";6187 const display_path = zig_source_path orelse "<stdin>";
6188 const source: [:0]const u8 = s: {6188 const source: [:0]const u8 = s: {
6189 var f = if (zig_source_path) |p| file: {6189 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| {
6191 fatal("unable to open file '{s}' for ast-check: {s}", .{ display_path, @errorName(err) });6191 fatal("unable to open file '{s}' for ast-check: {s}", .{ display_path, @errorName(err) });
6192 };6192 };
6193 } else Io.File.stdin();6193 } else Io.File.stdin();
...@@ -6494,7 +6494,7 @@ fn cmdDumpZir(arena: Allocator, io: Io, args: []const []const u8) !void {...@@ -6494,7 +6494,7 @@ fn cmdDumpZir(arena: Allocator, io: Io, args: []const []const u8) !void {
64946494
6495 const cache_file = args[0];6495 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| {
6498 fatal("unable to open zir cache file for dumping '{s}': {s}", .{ cache_file, @errorName(err) });6498 fatal("unable to open zir cache file for dumping '{s}': {s}", .{ cache_file, @errorName(err) });
6499 };6499 };
6500 defer f.close(io);6500 defer f.close(io);
...@@ -6541,7 +6541,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {...@@ -6541,7 +6541,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {
6541 const new_source_path = args[1];6541 const new_source_path = args[1];
65426542
6543 const old_source = source: {6543 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|
6545 fatal("unable to open old source file '{s}': {s}", .{ old_source_path, @errorName(err) });6545 fatal("unable to open old source file '{s}': {s}", .{ old_source_path, @errorName(err) });
6546 defer f.close(io);6546 defer f.close(io);
6547 var file_reader: Io.File.Reader = f.reader(io, &stdin_buffer);6547 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 {...@@ -6549,7 +6549,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {
6549 fatal("unable to read old source file '{s}': {s}", .{ old_source_path, @errorName(err) });6549 fatal("unable to read old source file '{s}': {s}", .{ old_source_path, @errorName(err) });
6550 };6550 };
6551 const new_source = source: {6551 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|
6553 fatal("unable to open new source file '{s}': {s}", .{ new_source_path, @errorName(err) });6553 fatal("unable to open new source file '{s}': {s}", .{ new_source_path, @errorName(err) });
6554 defer f.close(io);6554 defer f.close(io);
6555 var file_reader: Io.File.Reader = f.reader(io, &stdin_buffer);6555 var file_reader: Io.File.Reader = f.reader(io, &stdin_buffer);
...@@ -6845,7 +6845,7 @@ fn accessFrameworkPath(...@@ -6845,7 +6845,7 @@ fn accessFrameworkPath(
6845 framework_dir_path, framework_name, framework_name, ext,6845 framework_dir_path, framework_name, framework_name, ext,
6846 });6846 });
6847 try checked_paths.print("\n {s}", .{test_path.items});6847 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) {
6849 error.FileNotFound => continue,6849 error.FileNotFound => continue,
6850 else => |e| fatal("unable to search for {s} framework '{s}': {s}", .{6850 else => |e| fatal("unable to search for {s} framework '{s}': {s}", .{
6851 ext, test_path.items, @errorName(e),6851 ext, test_path.items, @errorName(e),
...@@ -6957,7 +6957,7 @@ fn cmdFetch(...@@ -6957,7 +6957,7 @@ fn cmdFetch(
6957 var global_cache_directory: Directory = l: {6957 var global_cache_directory: Directory = l: {
6958 const p = override_global_cache_dir orelse try introspect.resolveGlobalCacheDir(arena);6958 const p = override_global_cache_dir orelse try introspect.resolveGlobalCacheDir(arena);
6959 break :l .{6959 break :l .{
6960 .handle = try fs.cwd().makeOpenPath(p, .{}),6960 .handle = try Io.Dir.cwd().makeOpenPath(p, .{}),
6961 .path = p,6961 .path = p,
6962 };6962 };
6963 };6963 };
...@@ -7260,7 +7260,7 @@ fn findBuildRoot(arena: Allocator, options: FindBuildRootOptions) !BuildRoot {...@@ -7260,7 +7260,7 @@ fn findBuildRoot(arena: Allocator, options: FindBuildRootOptions) !BuildRoot {
72607260
7261 if (options.build_file) |bf| {7261 if (options.build_file) |bf| {
7262 if (fs.path.dirname(bf)) |dirname| {7262 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| {
7264 fatal("unable to open directory to build file from argument 'build-file', '{s}': {s}", .{ dirname, @errorName(err) });7264 fatal("unable to open directory to build file from argument 'build-file', '{s}': {s}", .{ dirname, @errorName(err) });
7265 };7265 };
7266 return .{7266 return .{
...@@ -7272,7 +7272,7 @@ fn findBuildRoot(arena: Allocator, options: FindBuildRootOptions) !BuildRoot {...@@ -7272,7 +7272,7 @@ fn findBuildRoot(arena: Allocator, options: FindBuildRootOptions) !BuildRoot {
72727272
7273 return .{7273 return .{
7274 .build_zig_basename = build_zig_basename,7274 .build_zig_basename = build_zig_basename,
7275 .directory = .{ .path = null, .handle = fs.cwd() },7275 .directory = .{ .path = null, .handle = Io.Dir.cwd() },
7276 .cleanup_build_dir = null,7276 .cleanup_build_dir = null,
7277 };7277 };
7278 }7278 }
...@@ -7280,8 +7280,8 @@ fn findBuildRoot(arena: Allocator, options: FindBuildRootOptions) !BuildRoot {...@@ -7280,8 +7280,8 @@ fn findBuildRoot(arena: Allocator, options: FindBuildRootOptions) !BuildRoot {
7280 var dirname: []const u8 = cwd_path;7280 var dirname: []const u8 = cwd_path;
7281 while (true) {7281 while (true) {
7282 const joined_path = try fs.path.join(arena, &[_][]const u8{ dirname, build_zig_basename });7282 const joined_path = try fs.path.join(arena, &[_][]const u8{ dirname, build_zig_basename });
7283 if (fs.cwd().access(joined_path, .{})) |_| {7283 if (Io.Dir.cwd().access(joined_path, .{})) |_| {
7284 const dir = fs.cwd().openDir(dirname, .{}) catch |err| {7284 const dir = Io.Dir.cwd().openDir(dirname, .{}) catch |err| {
7285 fatal("unable to open directory while searching for build.zig file, '{s}': {s}", .{ dirname, @errorName(err) });7285 fatal("unable to open directory while searching for build.zig file, '{s}': {s}", .{ dirname, @errorName(err) });
7286 };7286 };
7287 return .{7287 return .{
...@@ -7443,7 +7443,7 @@ const Templates = struct {...@@ -7443,7 +7443,7 @@ const Templates = struct {
7443 }7443 }
7444};7444};
7445fn writeSimpleTemplateFile(io: Io, file_name: []const u8, comptime fmt: []const u8, args: anytype) !void {7445fn 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 });
7447 defer f.close(io);7447 defer f.close(io);
7448 var buf: [4096]u8 = undefined;7448 var buf: [4096]u8 = undefined;
7449 var fw = f.writer(&buf);7449 var fw = f.writer(&buf);
...@@ -7591,7 +7591,7 @@ fn addLibDirectoryWarn2(...@@ -7591,7 +7591,7 @@ fn addLibDirectoryWarn2(
7591 ignore_not_found: bool,7591 ignore_not_found: bool,
7592) void {7592) void {
7593 lib_directories.appendAssumeCapacity(.{7593 lib_directories.appendAssumeCapacity(.{
7594 .handle = fs.cwd().openDir(path, .{}) catch |err| {7594 .handle = Io.Dir.cwd().openDir(path, .{}) catch |err| {
7595 if (err == error.FileNotFound and ignore_not_found) return;7595 if (err == error.FileNotFound and ignore_not_found) return;
7596 warn("unable to open library directory '{s}': {s}", .{ path, @errorName(err) });7596 warn("unable to open library directory '{s}': {s}", .{ path, @errorName(err) });
7597 return;7597 return;