aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/Build.zig2
-rw-r--r--lib/std/Build/Cache/Path.zig4
-rw-r--r--lib/std/Build/Step.zig12
-rw-r--r--lib/std/Build/Step/InstallDir.zig2
-rw-r--r--lib/std/Build/Step/Run.zig47
-rw-r--r--lib/std/Build/Step/WriteFile.zig9
-rw-r--r--lib/std/Io.zig4
-rw-r--r--lib/std/Io/Dir.zig16
-rw-r--r--lib/std/Io/Threaded.zig13
-rw-r--r--lib/std/Io/test.zig2
-rw-r--r--lib/std/debug.zig8
-rw-r--r--lib/std/fs/test.zig24
-rw-r--r--lib/std/posix.zig61
-rw-r--r--lib/std/posix/test.zig12
-rw-r--r--lib/std/zig/LibCInstallation.zig10
-rw-r--r--lib/std/zig/llvm/Builder.zig4
-rw-r--r--lib/std/zig/system.zig3
17 files changed, 91 insertions, 142 deletions
diff --git a/lib/std/Build.zig b/lib/std/Build.zig
index 1eff8813e5..746b41860b 100644
--- a/lib/std/Build.zig
+++ b/lib/std/Build.zig
@@ -1699,7 +1699,7 @@ pub fn addCheckFile(
return Step.CheckFile.create(b, file_source, options);
}
-pub fn truncateFile(b: *Build, dest_path: []const u8) (Io.Dir.MakeError || Io.Dir.StatFileError)!void {
+pub fn truncateFile(b: *Build, dest_path: []const u8) (Io.Dir.MakeError || Io.Dir.StatPathError)!void {
const io = b.graph.io;
if (b.verbose) log.info("truncate {s}", .{dest_path});
const cwd = Io.Dir.cwd();
diff --git a/lib/std/Build/Cache/Path.zig b/lib/std/Build/Cache/Path.zig
index 941948a9cd..759eb143b8 100644
--- a/lib/std/Build/Cache/Path.zig
+++ b/lib/std/Build/Cache/Path.zig
@@ -118,14 +118,14 @@ pub fn atomicFile(
return p.root_dir.handle.atomicFile(joined_path, options);
}
-pub fn access(p: Path, sub_path: []const u8, flags: Io.Dir.AccessOptions) !void {
+pub fn access(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.AccessOptions) !void {
var buf: [fs.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
- return p.root_dir.handle.access(joined_path, flags);
+ return p.root_dir.handle.access(io, joined_path, flags);
}
pub fn makePath(p: Path, io: Io, sub_path: []const u8) !void {
diff --git a/lib/std/Build/Step.zig b/lib/std/Build/Step.zig
index 2ec1c0ef31..f66f8df4c8 100644
--- a/lib/std/Build/Step.zig
+++ b/lib/std/Build/Step.zig
@@ -519,19 +519,21 @@ pub fn installFile(s: *Step, src_lazy_path: Build.LazyPath, dest_path: []const u
/// Wrapper around `Io.Dir.makePathStatus` that handles verbose and error output.
pub fn installDir(s: *Step, dest_path: []const u8) !Io.Dir.MakePathStatus {
const b = s.owner;
+ const io = b.graph.io;
try handleVerbose(b, null, &.{ "install", "-d", dest_path });
- return Io.Dir.cwd().makePathStatus(dest_path) catch |err|
+ return Io.Dir.cwd().makePathStatus(io, dest_path, .default_dir) catch |err|
return s.fail("unable to create dir '{s}': {t}", .{ dest_path, err });
}
fn zigProcessUpdate(s: *Step, zp: *ZigProcess, watch: bool, web_server: ?*Build.WebServer, gpa: Allocator) !?Path {
const b = s.owner;
const arena = b.allocator;
+ const io = b.graph.io;
var timer = try std.time.Timer.start();
- try sendMessage(zp.child.stdin.?, .update);
- if (!watch) try sendMessage(zp.child.stdin.?, .exit);
+ try sendMessage(io, zp.child.stdin.?, .update);
+ if (!watch) try sendMessage(io, zp.child.stdin.?, .exit);
var result: ?Path = null;
@@ -668,12 +670,12 @@ fn clearZigProcess(s: *Step, gpa: Allocator) void {
}
}
-fn sendMessage(file: Io.File, tag: std.zig.Client.Message.Tag) !void {
+fn sendMessage(io: Io, file: Io.File, tag: std.zig.Client.Message.Tag) !void {
const header: std.zig.Client.Message.Header = .{
.tag = tag,
.bytes_len = 0,
};
- var w = file.writer(&.{});
+ var w = file.writer(io, &.{});
w.interface.writeStruct(header, .little) catch |err| switch (err) {
error.WriteFailed => return w.err.?,
};
diff --git a/lib/std/Build/Step/InstallDir.zig b/lib/std/Build/Step/InstallDir.zig
index 788d5565a7..d03e72ca75 100644
--- a/lib/std/Build/Step/InstallDir.zig
+++ b/lib/std/Build/Step/InstallDir.zig
@@ -71,7 +71,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
defer src_dir.close(io);
var it = try src_dir.walk(arena);
var all_cached = true;
- next_entry: while (try it.next()) |entry| {
+ next_entry: while (try it.next(io)) |entry| {
for (install_dir.options.exclude_extensions) |ext| {
if (mem.endsWith(u8, entry.path, ext)) continue :next_entry;
}
diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig
index 54e77bd614..f6b29635c1 100644
--- a/lib/std/Build/Step/Run.zig
+++ b/lib/std/Build/Step/Run.zig
@@ -1310,7 +1310,7 @@ fn runCommand(
const need_cross_libc = exe.is_linking_libc and
(root_target.isGnuLibC() or (root_target.isMuslLibC() and exe.linkage == .dynamic));
const other_target = exe.root_module.resolved_target.?.result;
- switch (std.zig.system.getExternalExecutor(&b.graph.host.result, &other_target, .{
+ switch (std.zig.system.getExternalExecutor(io, &b.graph.host.result, &other_target, .{
.qemu_fixes_dl = need_cross_libc and b.libc_runtimes_dir != null,
.link_libc = exe.is_linking_libc,
})) {
@@ -1702,7 +1702,7 @@ fn evalZigTest(
});
var child_killed = false;
defer if (!child_killed) {
- _ = child.kill() catch {};
+ _ = child.kill(io) catch {};
poller.deinit();
run.step.result_peak_rss = @max(
run.step.result_peak_rss,
@@ -1732,7 +1732,7 @@ fn evalZigTest(
child.stdin = null;
poller.deinit();
child_killed = true;
- const term = try child.wait();
+ const term = try child.wait(io);
run.step.result_peak_rss = @max(
run.step.result_peak_rss,
child.resource_usage_statistics.getMaxRss() orelse 0,
@@ -1752,7 +1752,7 @@ fn evalZigTest(
child.stdin = null;
poller.deinit();
child_killed = true;
- const term = try child.wait();
+ const term = try child.wait(io);
run.step.result_peak_rss = @max(
run.step.result_peak_rss,
child.resource_usage_statistics.getMaxRss() orelse 0,
@@ -1840,6 +1840,7 @@ fn pollZigTest(
switch (ctx.fuzz.mode) {
.forever => {
sendRunFuzzTestMessage(
+ io,
child.stdin.?,
ctx.unit_test_index,
.forever,
@@ -1848,6 +1849,7 @@ fn pollZigTest(
},
.limit => |limit| {
sendRunFuzzTestMessage(
+ io,
child.stdin.?,
ctx.unit_test_index,
.iterations,
@@ -1857,11 +1859,11 @@ fn pollZigTest(
}
} else if (opt_metadata.*) |*md| {
// Previous unit test process died or was killed; we're continuing where it left off
- requestNextTest(child.stdin.?, md, &sub_prog_node) catch |err| return .{ .write_failed = err };
+ requestNextTest(io, child.stdin.?, md, &sub_prog_node) catch |err| return .{ .write_failed = err };
} else {
// Running unit tests normally
run.fuzz_tests.clearRetainingCapacity();
- sendMessage(child.stdin.?, .query_test_metadata) catch |err| return .{ .write_failed = err };
+ sendMessage(io, child.stdin.?, .query_test_metadata) catch |err| return .{ .write_failed = err };
}
var active_test_index: ?u32 = null;
@@ -1977,7 +1979,7 @@ fn pollZigTest(
active_test_index = null;
if (timer) |*t| t.reset();
- requestNextTest(child.stdin.?, &opt_metadata.*.?, &sub_prog_node) catch |err| return .{ .write_failed = err };
+ requestNextTest(io, child.stdin.?, &opt_metadata.*.?, &sub_prog_node) catch |err| return .{ .write_failed = err };
},
.test_started => {
active_test_index = opt_metadata.*.?.next_index - 1;
@@ -2026,7 +2028,7 @@ fn pollZigTest(
active_test_index = null;
if (timer) |*t| md.ns_per_test[tr_hdr.index] = t.lap();
- requestNextTest(child.stdin.?, md, &sub_prog_node) catch |err| return .{ .write_failed = err };
+ requestNextTest(io, child.stdin.?, md, &sub_prog_node) catch |err| return .{ .write_failed = err };
},
.coverage_id => {
coverage_id = body_r.takeInt(u64, .little) catch unreachable;
@@ -2097,7 +2099,7 @@ pub const CachedTestMetadata = struct {
}
};
-fn requestNextTest(in: Io.File, metadata: *TestMetadata, sub_prog_node: *?std.Progress.Node) !void {
+fn requestNextTest(io: Io, in: Io.File, metadata: *TestMetadata, sub_prog_node: *?std.Progress.Node) !void {
while (metadata.next_index < metadata.names.len) {
const i = metadata.next_index;
metadata.next_index += 1;
@@ -2108,31 +2110,31 @@ fn requestNextTest(in: Io.File, metadata: *TestMetadata, sub_prog_node: *?std.Pr
if (sub_prog_node.*) |n| n.end();
sub_prog_node.* = metadata.prog_node.start(name, 0);
- try sendRunTestMessage(in, .run_test, i);
+ try sendRunTestMessage(io, in, .run_test, i);
return;
} else {
metadata.next_index = std.math.maxInt(u32); // indicate that all tests are done
- try sendMessage(in, .exit);
+ try sendMessage(io, in, .exit);
}
}
-fn sendMessage(file: Io.File, tag: std.zig.Client.Message.Tag) !void {
+fn sendMessage(io: Io, file: Io.File, tag: std.zig.Client.Message.Tag) !void {
const header: std.zig.Client.Message.Header = .{
.tag = tag,
.bytes_len = 0,
};
- var w = file.writer(&.{});
+ var w = file.writer(io, &.{});
w.interface.writeStruct(header, .little) catch |err| switch (err) {
error.WriteFailed => return w.err.?,
};
}
-fn sendRunTestMessage(file: Io.File, tag: std.zig.Client.Message.Tag, index: u32) !void {
+fn sendRunTestMessage(io: Io, file: Io.File, tag: std.zig.Client.Message.Tag, index: u32) !void {
const header: std.zig.Client.Message.Header = .{
.tag = tag,
.bytes_len = 4,
};
- var w = file.writer(&.{});
+ var w = file.writer(io, &.{});
w.interface.writeStruct(header, .little) catch |err| switch (err) {
error.WriteFailed => return w.err.?,
};
@@ -2142,6 +2144,7 @@ fn sendRunTestMessage(file: Io.File, tag: std.zig.Client.Message.Tag, index: u32
}
fn sendRunFuzzTestMessage(
+ io: Io,
file: Io.File,
index: u32,
kind: std.Build.abi.fuzz.LimitKind,
@@ -2151,7 +2154,7 @@ fn sendRunFuzzTestMessage(
.tag = .start_fuzzing,
.bytes_len = 4 + 1 + 8,
};
- var w = file.writer(&.{});
+ var w = file.writer(io, &.{});
w.interface.writeStruct(header, .little) catch |err| switch (err) {
error.WriteFailed => return w.err.?,
};
@@ -2172,14 +2175,14 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult {
const arena = b.allocator;
try child.spawn();
- errdefer _ = child.kill() catch {};
+ errdefer _ = child.kill(io) catch {};
try child.waitForSpawn();
switch (run.stdin) {
.bytes => |bytes| {
- child.stdin.?.writeAll(bytes) catch |err| {
- return run.step.fail("unable to write stdin: {s}", .{@errorName(err)});
+ child.stdin.?.writeStreamingAll(io, bytes) catch |err| {
+ return run.step.fail("unable to write stdin: {t}", .{err});
};
child.stdin.?.close(io);
child.stdin = null;
@@ -2187,14 +2190,14 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult {
.lazy_path => |lazy_path| {
const path = lazy_path.getPath3(b, &run.step);
const file = path.root_dir.handle.openFile(io, path.subPathOrDot(), .{}) catch |err| {
- return run.step.fail("unable to open stdin file: {s}", .{@errorName(err)});
+ return run.step.fail("unable to open stdin file: {t}", .{err});
};
defer file.close(io);
// TODO https://github.com/ziglang/zig/issues/23955
var read_buffer: [1024]u8 = undefined;
var file_reader = file.reader(io, &read_buffer);
var write_buffer: [1024]u8 = undefined;
- var stdin_writer = child.stdin.?.writer(&write_buffer);
+ var stdin_writer = child.stdin.?.writer(io, &write_buffer);
_ = stdin_writer.interface.sendFileAll(&file_reader, .unlimited) catch |err| switch (err) {
error.ReadFailed => return run.step.fail("failed to read from {f}: {t}", .{
path, file_reader.err.?,
@@ -2267,7 +2270,7 @@ fn evalGeneric(run: *Run, child: *std.process.Child) !EvalGenericResult {
run.step.result_peak_rss = child.resource_usage_statistics.getMaxRss() orelse 0;
return .{
- .term = try child.wait(),
+ .term = try child.wait(io),
.stdout = stdout_bytes,
.stderr = stderr_bytes,
};
diff --git a/lib/std/Build/Step/WriteFile.zig b/lib/std/Build/Step/WriteFile.zig
index 21346959e7..94b04b4212 100644
--- a/lib/std/Build/Step/WriteFile.zig
+++ b/lib/std/Build/Step/WriteFile.zig
@@ -228,7 +228,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
var it = try src_dir.walk(gpa);
defer it.deinit();
- while (try it.next()) |entry| {
+ while (try it.next(io)) |entry| {
if (!dir.options.pathIncluded(entry.path)) continue;
switch (entry.kind) {
@@ -259,11 +259,8 @@ fn make(step: *Step, options: Step.MakeOptions) !void {
write_file.generated_directory.path = try b.cache_root.join(arena, &.{ "o", &digest });
- var cache_dir = b.cache_root.handle.makeOpenPath(cache_path, .{}) catch |err| {
- return step.fail("unable to make path '{f}{s}': {s}", .{
- b.cache_root, cache_path, @errorName(err),
- });
- };
+ var cache_dir = b.cache_root.handle.makeOpenPath(io, cache_path, .{}) catch |err|
+ return step.fail("unable to make path '{f}{s}': {t}", .{ b.cache_root, cache_path, err });
defer cache_dir.close(io);
for (write_file.files.items) |file| {
diff --git a/lib/std/Io.zig b/lib/std/Io.zig
index ad0764ebe1..7f5f049d34 100644
--- a/lib/std/Io.zig
+++ b/lib/std/Io.zig
@@ -664,13 +664,13 @@ pub const VTable = struct {
dirMake: *const fn (?*anyopaque, Dir, []const u8, Dir.Permissions) Dir.MakeError!void,
dirMakePath: *const fn (?*anyopaque, Dir, []const u8, Dir.Permissions) Dir.MakePathError!Dir.MakePathStatus,
- dirMakeOpenPath: *const fn (?*anyopaque, Dir, []const u8, Dir.OpenOptions) Dir.MakeOpenPathError!Dir,
+ dirMakeOpenPath: *const fn (?*anyopaque, Dir, []const u8, Dir.Permissions, Dir.OpenOptions) Dir.MakeOpenPathError!Dir,
+ dirOpenDir: *const fn (?*anyopaque, Dir, []const u8, Dir.OpenOptions) Dir.OpenError!Dir,
dirStat: *const fn (?*anyopaque, Dir) Dir.StatError!Dir.Stat,
dirStatPath: *const fn (?*anyopaque, Dir, []const u8, Dir.StatPathOptions) Dir.StatPathError!File.Stat,
dirAccess: *const fn (?*anyopaque, Dir, []const u8, Dir.AccessOptions) Dir.AccessError!void,
dirCreateFile: *const fn (?*anyopaque, Dir, []const u8, File.CreateFlags) File.OpenError!File,
dirOpenFile: *const fn (?*anyopaque, Dir, []const u8, File.OpenFlags) File.OpenError!File,
- dirOpenDir: *const fn (?*anyopaque, Dir, []const u8, Dir.OpenOptions) Dir.OpenError!Dir,
dirClose: *const fn (?*anyopaque, []const Dir) void,
dirRead: *const fn (?*anyopaque, *Dir.Reader, []Dir.Entry) Dir.Reader.Error!usize,
dirRealPath: *const fn (?*anyopaque, Dir, path_name: []const u8, out_buffer: []u8) Dir.RealPathError!usize,
diff --git a/lib/std/Io/Dir.zig b/lib/std/Io/Dir.zig
index 58f81cbb90..755ce924ad 100644
--- a/lib/std/Io/Dir.zig
+++ b/lib/std/Io/Dir.zig
@@ -191,7 +191,7 @@ pub const SelectiveWalker = struct {
while (self.stack.items.len > 0) {
const top = &self.stack.items[self.stack.items.len - 1];
var dirname_len = top.dirname_len;
- if (top.iter.next() catch |err| {
+ if (top.iter.next(io) catch |err| {
// If we get an error, then we want the user to be able to continue
// walking if they want, which means that we need to pop the directory
// that errored from the stack. Otherwise, all future `next` calls would
@@ -302,7 +302,7 @@ pub const Walker = struct {
dir: Dir,
basename: [:0]const u8,
path: [:0]const u8,
- kind: Dir.Entry.Kind,
+ kind: File.Kind,
/// Returns the depth of the entry relative to the initial directory.
/// Returns 1 for a direct child of the initial directory, 2 for an entry
@@ -320,10 +320,10 @@ pub const Walker = struct {
/// After each call to this function, and on deinit(), the memory returned
/// from this function becomes invalid. A copy must be made in order to keep
/// a reference to the path.
- pub fn next(self: *Walker) !?Walker.Entry {
- const entry = try self.inner.next();
+ pub fn next(self: *Walker, io: Io) !?Walker.Entry {
+ const entry = try self.inner.next(io);
if (entry != null and entry.?.kind == .directory) {
- try self.inner.enter(entry.?);
+ try self.inner.enter(io, entry.?);
}
return entry;
}
@@ -495,7 +495,7 @@ pub const WriteFileOptions = struct {
flags: File.CreateFlags = .{},
};
-pub const WriteFileError = File.WriteError || File.OpenError;
+pub const WriteFileError = File.Writer.Error || File.OpenError;
/// Writes content to the file system, using the file creation flags provided.
pub fn writeFile(dir: Dir, io: Io, options: WriteFileOptions) WriteFileError!void {
@@ -556,11 +556,11 @@ pub fn updateFile(
}
if (path.dirname(dest_path)) |dirname| {
- try dest_dir.makePath(io, dirname, .default_dir);
+ try dest_dir.makePath(io, dirname);
}
var buffer: [1000]u8 = undefined; // Used only when direct fd-to-fd is not available.
- var atomic_file = try Dir.atomicFile(dest_dir, dest_path, .{
+ var atomic_file = try dest_dir.atomicFile(io, dest_path, .{
.permissions = actual_permissions,
.write_buffer = &buffer,
});
diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig
index 4ee1d5db53..16e8930267 100644
--- a/lib/std/Io/Threaded.zig
+++ b/lib/std/Io/Threaded.zig
@@ -12,7 +12,7 @@ const std = @import("../std.zig");
const Io = std.Io;
const net = std.Io.net;
const File = std.Io.File;
-const Dir = std.Dir;
+const Dir = std.Io.Dir;
const HostName = std.Io.net.HostName;
const IpAddress = std.Io.net.IpAddress;
const Allocator = std.mem.Allocator;
@@ -1614,13 +1614,14 @@ fn dirMakeOpenPathPosix(
userdata: ?*anyopaque,
dir: Dir,
sub_path: []const u8,
+ permissions: Dir.Permissions,
options: Dir.OpenOptions,
) Dir.MakeOpenPathError!Dir {
const t: *Threaded = @ptrCast(@alignCast(userdata));
const t_io = ioBasic(t);
- return dirOpenDirPosix(t, dir, sub_path, options) catch |err| switch (err) {
+ return dirOpenDirPosix(t, dir, sub_path, permissions, options) catch |err| switch (err) {
error.FileNotFound => {
- try dir.makePath(t_io, sub_path);
+ _ = try dir.makePathStatus(t_io, sub_path, permissions);
return dirOpenDirPosix(t, dir, sub_path, options);
},
else => |e| return e,
@@ -1631,12 +1632,15 @@ fn dirMakeOpenPathWindows(
userdata: ?*anyopaque,
dir: Dir,
sub_path: []const u8,
+ permissions: Dir.Permissions,
options: Dir.OpenOptions,
) Dir.MakeOpenPathError!Dir {
const t: *Threaded = @ptrCast(@alignCast(userdata));
const current_thread = Thread.getCurrent(t);
const w = windows;
+ _ = permissions; // TODO apply these permissions
+
var it = std.fs.path.componentIterator(sub_path);
// If there are no components in the path, then create a dummy component with the full path.
var component: std.fs.path.NativeComponentIterator.Component = it.last() orelse .{
@@ -1746,13 +1750,14 @@ fn dirMakeOpenPathWasi(
userdata: ?*anyopaque,
dir: Dir,
sub_path: []const u8,
+ permissions: Dir.Permissions,
options: Dir.OpenOptions,
) Dir.MakeOpenPathError!Dir {
const t: *Threaded = @ptrCast(@alignCast(userdata));
const t_io = ioBasic(t);
return dirOpenDirWasi(t, dir, sub_path, options) catch |err| switch (err) {
error.FileNotFound => {
- try dir.makePath(t_io, sub_path);
+ _ = try dir.makePathStatus(t_io, sub_path, permissions);
return dirOpenDirWasi(t, dir, sub_path, options);
},
else => |e| return e,
diff --git a/lib/std/Io/test.zig b/lib/std/Io/test.zig
index e911031c7f..9763fb2397 100644
--- a/lib/std/Io/test.zig
+++ b/lib/std/Io/test.zig
@@ -30,7 +30,7 @@ test "write a file, read it, then delete it" {
var file = try tmp.dir.createFile(io, tmp_file_name, .{});
defer file.close(io);
- var file_writer = file.writer(&.{});
+ var file_writer = file.writer(io, &.{});
const st = &file_writer.interface;
try st.print("begin", .{});
try st.writeAll(&data);
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 34f740bfee..39207f938d 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -1279,7 +1279,7 @@ test printLineFromFile {
const overlap = 10;
var buf: [16]u8 = undefined;
- var file_writer = file.writer(&buf);
+ var file_writer = file.writer(io, &buf);
const writer = &file_writer.interface;
try writer.splatByteAll('a', std.heap.page_size_min - overlap);
try writer.writeByte('\n');
@@ -1296,7 +1296,7 @@ test printLineFromFile {
const path = try fs.path.join(gpa, &.{ test_dir_path, "file_ends_on_page_boundary.zig" });
defer gpa.free(path);
- var file_writer = file.writer(&.{});
+ var file_writer = file.writer(io, &.{});
const writer = &file_writer.interface;
try writer.splatByteAll('a', std.heap.page_size_max);
@@ -1310,7 +1310,7 @@ test printLineFromFile {
const path = try fs.path.join(gpa, &.{ test_dir_path, "very_long_first_line_spanning_multiple_pages.zig" });
defer gpa.free(path);
- var file_writer = file.writer(&.{});
+ var file_writer = file.writer(io, &.{});
const writer = &file_writer.interface;
try writer.splatByteAll('a', 3 * std.heap.page_size_max);
@@ -1336,7 +1336,7 @@ test printLineFromFile {
const path = try fs.path.join(gpa, &.{ test_dir_path, "file_of_newlines.zig" });
defer gpa.free(path);
- var file_writer = file.writer(&.{});
+ var file_writer = file.writer(io, &.{});
const writer = &file_writer.interface;
const real_file_start = 3 * std.heap.page_size_min;
try writer.splatByteAll('\n', real_file_start);
diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig
index bc84500419..59bacff2d0 100644
--- a/lib/std/fs/test.zig
+++ b/lib/std/fs/test.zig
@@ -1206,8 +1206,8 @@ test "deleteTree does not follow symlinks" {
try tmp.dir.deleteTree("a");
- try testing.expectError(error.FileNotFound, tmp.dir.access("a", .{}));
- try tmp.dir.access("b", .{});
+ try testing.expectError(error.FileNotFound, tmp.dir.access(io, "a", .{}));
+ try tmp.dir.access(io, "b", .{});
}
test "deleteTree on a symlink" {
@@ -1221,16 +1221,16 @@ test "deleteTree on a symlink" {
try setupSymlink(tmp.dir, "file", "filelink", .{});
try tmp.dir.deleteTree("filelink");
- try testing.expectError(error.FileNotFound, tmp.dir.access("filelink", .{}));
- try tmp.dir.access("file", .{});
+ try testing.expectError(error.FileNotFound, tmp.dir.access(io, "filelink", .{}));
+ try tmp.dir.access(io, "file", .{});
// Symlink to a directory
try tmp.dir.makePath(io, "dir");
try setupSymlink(tmp.dir, "dir", "dirlink", .{ .is_directory = true });
try tmp.dir.deleteTree("dirlink");
- try testing.expectError(error.FileNotFound, tmp.dir.access("dirlink", .{}));
- try tmp.dir.access("dir", .{});
+ try testing.expectError(error.FileNotFound, tmp.dir.access(io, "dirlink", .{}));
+ try tmp.dir.access(io, "dir", .{});
}
test "makePath, put some files in it, deleteTree" {
@@ -1358,8 +1358,8 @@ test "makepath relative walks" {
// On Windows, .. is resolved before passing the path to NtCreateFile,
// meaning everything except `first/C` drops out.
try expectDir(io, tmp.dir, "first" ++ fs.path.sep_str ++ "C");
- try testing.expectError(error.FileNotFound, tmp.dir.access("second", .{}));
- try testing.expectError(error.FileNotFound, tmp.dir.access("third", .{}));
+ try testing.expectError(error.FileNotFound, tmp.dir.access(io, "second", .{}));
+ try testing.expectError(error.FileNotFound, tmp.dir.access(io, "third", .{}));
},
else => {
try expectDir(io, tmp.dir, "first" ++ fs.path.sep_str ++ "A");
@@ -1561,10 +1561,10 @@ test "access file" {
const file_path = try ctx.transformPath("os_test_tmp" ++ fs.path.sep_str ++ "file.txt");
try ctx.dir.makePath(io, dir_path);
- try testing.expectError(error.FileNotFound, ctx.dir.access(file_path, .{}));
+ try testing.expectError(error.FileNotFound, ctx.dir.access(io, file_path, .{}));
try ctx.dir.writeFile(.{ .sub_path = file_path, .data = "" });
- try ctx.dir.access(file_path, .{});
+ try ctx.dir.access(io, file_path, .{});
try ctx.dir.deleteTree(dir_path);
}
}.impl);
@@ -2036,13 +2036,13 @@ test "'.' and '..' in Io.Dir functions" {
const update_path = try ctx.transformPath("./subdir/../update");
try ctx.dir.makeDir(subdir_path);
- try ctx.dir.access(subdir_path, .{});
+ try ctx.dir.access(io, subdir_path, .{});
var created_subdir = try ctx.dir.openDir(io, subdir_path, .{});
created_subdir.close(io);
const created_file = try ctx.dir.createFile(io, file_path, .{});
created_file.close(io);
- try ctx.dir.access(file_path, .{});
+ try ctx.dir.access(io, file_path, .{});
try ctx.dir.copyFile(file_path, ctx.dir, copy_path, .{});
try ctx.dir.rename(copy_path, rename_path);
diff --git a/lib/std/posix.zig b/lib/std/posix.zig
index 42429a4993..609cf62e82 100644
--- a/lib/std/posix.zig
+++ b/lib/std/posix.zig
@@ -2842,67 +2842,6 @@ pub fn msync(memory: []align(page_size_min) u8, flags: i32) MSyncError!void {
}
}
-pub const AccessError = error{
- AccessDenied,
- PermissionDenied,
- FileNotFound,
- NameTooLong,
- InputOutput,
- SystemResources,
- FileBusy,
- SymLinkLoop,
- ReadOnlyFileSystem,
- /// WASI: file paths must be valid UTF-8.
- /// Windows: file paths provided by the user must be valid WTF-8.
- /// https://wtf-8.codeberg.page/
- BadPathName,
- Canceled,
-} || UnexpectedError;
-
-/// check user's permissions for a file
-///
-/// * On Windows, asserts `path` is valid [WTF-8](https://wtf-8.codeberg.page/).
-/// * On WASI, invalid UTF-8 passed to `path` causes `error.BadPathName`.
-/// * On other platforms, `path` is an opaque sequence of bytes with no particular encoding.
-///
-/// On Windows, `mode` is ignored. This is a POSIX API that is only partially supported by
-/// Windows. See `fs` for the cross-platform file system API.
-pub fn access(path: []const u8, mode: u32) AccessError!void {
- if (native_os == .windows) {
- @compileError("use std.Io instead");
- } else if (native_os == .wasi and !builtin.link_libc) {
- @compileError("wasi doesn't support absolute paths");
- }
- const path_c = try toPosixPath(path);
- return accessZ(&path_c, mode);
-}
-
-/// Same as `access` except `path` is null-terminated.
-pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
- if (native_os == .windows) {
- @compileError("use std.Io instead");
- } else if (native_os == .wasi and !builtin.link_libc) {
- return access(mem.sliceTo(path, 0), mode);
- }
- switch (errno(system.access(path, mode))) {
- .SUCCESS => return,
- .ACCES => return error.AccessDenied,
- .PERM => return error.PermissionDenied,
- .ROFS => return error.ReadOnlyFileSystem,
- .LOOP => return error.SymLinkLoop,
- .TXTBSY => return error.FileBusy,
- .NOTDIR => return error.FileNotFound,
- .NOENT => return error.FileNotFound,
- .NAMETOOLONG => return error.NameTooLong,
- .INVAL => unreachable,
- .FAULT => unreachable,
- .IO => return error.InputOutput,
- .NOMEM => return error.SystemResources,
- .ILSEQ => return error.BadPathName,
- else => |err| return unexpectedErrno(err),
- }
-}
-
pub const PipeError = error{
SystemFdQuotaExceeded,
ProcessFdQuotaExceeded,
diff --git a/lib/std/posix/test.zig b/lib/std/posix/test.zig
index 169c5a70c2..af17f1f9ff 100644
--- a/lib/std/posix/test.zig
+++ b/lib/std/posix/test.zig
@@ -376,7 +376,7 @@ test "mmap" {
const file = try tmp.dir.createFile(io, test_out_file, .{});
defer file.close(io);
- var stream = file.writer(&.{});
+ var stream = file.writer(io, &.{});
var i: usize = 0;
while (i < alloc_size / @sizeOf(u32)) : (i += 1) {
@@ -741,6 +741,8 @@ test "access smoke test" {
if (native_os == .windows) return error.SkipZigTest;
if (native_os == .openbsd) return error.SkipZigTest;
+ const io = testing.io;
+
var tmp = tmpDir(.{});
defer tmp.cleanup();
@@ -761,9 +763,9 @@ test "access smoke test" {
const file_path = try fs.path.join(a, &.{ base_path, "some_file" });
defer a.free(file_path);
if (native_os == .windows) {
- try posix.access(file_path, posix.F_OK);
+ try posix.access(io, file_path, posix.F_OK);
} else {
- try posix.access(file_path, posix.F_OK | posix.W_OK | posix.R_OK);
+ try posix.access(io, file_path, posix.F_OK | posix.W_OK | posix.R_OK);
}
}
@@ -771,7 +773,7 @@ test "access smoke test" {
// Try to access() a non-existent file - should fail with error.FileNotFound
const file_path = try fs.path.join(a, &.{ base_path, "some_other_file" });
defer a.free(file_path);
- try expectError(error.FileNotFound, posix.access(file_path, posix.F_OK));
+ try expectError(error.FileNotFound, posix.access(io, file_path, posix.F_OK));
}
{
@@ -786,7 +788,7 @@ test "access smoke test" {
const file_path = try fs.path.join(a, &.{ base_path, "some_dir" });
defer a.free(file_path);
- try posix.access(file_path, posix.F_OK);
+ try posix.access(io, file_path, posix.F_OK);
}
}
diff --git a/lib/std/zig/LibCInstallation.zig b/lib/std/zig/LibCInstallation.zig
index a5c55d3522..f3dc73838f 100644
--- a/lib/std/zig/LibCInstallation.zig
+++ b/lib/std/zig/LibCInstallation.zig
@@ -357,7 +357,7 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, args: FindNativeOptions) F
}
if (self.sys_include_dir == null) {
- if (search_dir.access(sys_include_dir_example_file, .{})) |_| {
+ if (search_dir.access(io, sys_include_dir_example_file, .{})) |_| {
self.sys_include_dir = try allocator.dupeZ(u8, search_path);
} else |err| switch (err) {
error.FileNotFound => {},
@@ -402,7 +402,7 @@ fn findNativeIncludeDirWindows(
};
defer dir.close(io);
- dir.access("stdlib.h", .{}) catch |err| switch (err) {
+ dir.access(io, "stdlib.h", .{}) catch |err| switch (err) {
error.FileNotFound => continue,
else => return error.FileSystem,
};
@@ -450,7 +450,7 @@ fn findNativeCrtDirWindows(
};
defer dir.close(io);
- dir.access("ucrt.lib", .{}) catch |err| switch (err) {
+ dir.access(io, "ucrt.lib", .{}) catch |err| switch (err) {
error.FileNotFound => continue,
else => return error.FileSystem,
};
@@ -518,7 +518,7 @@ fn findNativeKernel32LibDir(
};
defer dir.close(io);
- dir.access("kernel32.lib", .{}) catch |err| switch (err) {
+ dir.access(io, "kernel32.lib", .{}) catch |err| switch (err) {
error.FileNotFound => continue,
else => return error.FileSystem,
};
@@ -554,7 +554,7 @@ fn findNativeMsvcIncludeDir(
};
defer dir.close(io);
- dir.access("vcruntime.h", .{}) catch |err| switch (err) {
+ dir.access(io, "vcruntime.h", .{}) catch |err| switch (err) {
error.FileNotFound => return error.LibCStdLibHeaderNotFound,
else => return error.FileSystem,
};
diff --git a/lib/std/zig/llvm/Builder.zig b/lib/std/zig/llvm/Builder.zig
index 443bdcc391..251c87defc 100644
--- a/lib/std/zig/llvm/Builder.zig
+++ b/lib/std/zig/llvm/Builder.zig
@@ -9589,8 +9589,8 @@ pub fn printToFilePath(b: *Builder, io: Io, dir: Io.Dir, path: []const u8) !void
try b.printToFile(io, file, &buffer);
}
-pub fn printToFile(b: *Builder, file: Io.File, buffer: []u8) !void {
- var fw = file.writer(buffer);
+pub fn printToFile(b: *Builder, io: Io, file: Io.File, buffer: []u8) !void {
+ var fw = file.writer(io, buffer);
try print(b, &fw.interface);
try fw.interface.flush();
}
diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig
index 9fa0546c3b..feed21efec 100644
--- a/lib/std/zig/system.zig
+++ b/lib/std/zig/system.zig
@@ -40,6 +40,7 @@ pub const GetExternalExecutorOptions = struct {
/// Return whether or not the given host is capable of running executables of
/// the other target.
pub fn getExternalExecutor(
+ io: Io,
host: *const std.Target,
candidate: *const std.Target,
options: GetExternalExecutorOptions,
@@ -70,7 +71,7 @@ pub fn getExternalExecutor(
if (os_match and cpu_ok) native: {
if (options.link_libc) {
if (candidate.dynamic_linker.get()) |candidate_dl| {
- Io.Dir.cwd().access(candidate_dl, .{}) catch {
+ Io.Dir.cwd().access(io, candidate_dl, .{}) catch {
bad_result = .{ .bad_dl = candidate_dl };
break :native;
};