mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
std.Io.Threaded: import File and Dir
This commit is contained in:
parent
470e2d6796
commit
78cbdec537
1 changed files with 165 additions and 163 deletions
|
|
@ -11,6 +11,8 @@ const is_debug = builtin.mode == .Debug;
|
|||
const std = @import("../std.zig");
|
||||
const Io = std.Io;
|
||||
const net = std.Io.net;
|
||||
const File = std.Io.File;
|
||||
const Dir = std.Dir;
|
||||
const HostName = std.Io.net.HostName;
|
||||
const IpAddress = std.Io.net.IpAddress;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
|
@ -1307,7 +1309,7 @@ const dirMake = switch (native_os) {
|
|||
else => dirMakePosix,
|
||||
};
|
||||
|
||||
fn dirMakePosix(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode: Io.Dir.Mode) Io.Dir.MakeError!void {
|
||||
fn dirMakePosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, mode: Dir.Mode) Dir.MakeError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -1353,7 +1355,7 @@ fn dirMakePosix(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode:
|
|||
}
|
||||
}
|
||||
|
||||
fn dirMakeWasi(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode: Io.Dir.Mode) Io.Dir.MakeError!void {
|
||||
fn dirMakeWasi(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, mode: Dir.Mode) Dir.MakeError!void {
|
||||
if (builtin.link_libc) return dirMakePosix(userdata, dir, sub_path, mode);
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
|
@ -1395,7 +1397,7 @@ fn dirMakeWasi(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode: I
|
|||
}
|
||||
}
|
||||
|
||||
fn dirMakeWindows(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode: Io.Dir.Mode) Io.Dir.MakeError!void {
|
||||
fn dirMakeWindows(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, mode: Dir.Mode) Dir.MakeError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
try current_thread.checkCancel();
|
||||
|
|
@ -1420,14 +1422,14 @@ fn dirMakeWindows(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, mode
|
|||
|
||||
fn dirMakePath(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
mode: Io.Dir.Mode,
|
||||
) Io.Dir.MakePathError!Io.Dir.MakePathStatus {
|
||||
mode: Dir.Mode,
|
||||
) Dir.MakePathError!Dir.MakePathStatus {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
|
||||
var it = std.fs.path.componentIterator(sub_path);
|
||||
var status: Io.Dir.MakePathStatus = .existed;
|
||||
var status: Dir.MakePathStatus = .existed;
|
||||
var component = it.last() orelse return error.BadPathName;
|
||||
while (true) {
|
||||
if (dirMake(t, dir, component.path, mode)) |_| {
|
||||
|
|
@ -1464,10 +1466,10 @@ const dirMakeOpenPath = switch (native_os) {
|
|||
|
||||
fn dirMakeOpenPathPosix(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
options: Io.Dir.OpenOptions,
|
||||
) Io.Dir.MakeOpenPathError!Io.Dir {
|
||||
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) {
|
||||
|
|
@ -1481,10 +1483,10 @@ fn dirMakeOpenPathPosix(
|
|||
|
||||
fn dirMakeOpenPathWindows(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
options: Io.Dir.OpenOptions,
|
||||
) Io.Dir.MakeOpenPathError!Io.Dir {
|
||||
options: Dir.OpenOptions,
|
||||
) Dir.MakeOpenPathError!Dir {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
const w = windows;
|
||||
|
|
@ -1507,7 +1509,7 @@ fn dirMakeOpenPathWindows(
|
|||
const is_last = it.peekNext() == null;
|
||||
const create_disposition: u32 = if (is_last) w.FILE_OPEN_IF else w.FILE_CREATE;
|
||||
|
||||
var result: Io.Dir = .{ .handle = undefined };
|
||||
var result: Dir = .{ .handle = undefined };
|
||||
|
||||
const path_len_bytes: u16 = @intCast(sub_path_w.len * 2);
|
||||
var nt_name: w.UNICODE_STRING = .{
|
||||
|
|
@ -1585,10 +1587,10 @@ fn dirMakeOpenPathWindows(
|
|||
|
||||
fn dirMakeOpenPathWasi(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
options: Io.Dir.OpenOptions,
|
||||
) Io.Dir.MakeOpenPathError!Io.Dir {
|
||||
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) {
|
||||
|
|
@ -1600,9 +1602,9 @@ fn dirMakeOpenPathWasi(
|
|||
};
|
||||
}
|
||||
|
||||
fn dirStat(userdata: ?*anyopaque, dir: Io.Dir) Io.Dir.StatError!Io.Dir.Stat {
|
||||
fn dirStat(userdata: ?*anyopaque, dir: Dir) Dir.StatError!Dir.Stat {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const file: Io.File = .{ .handle = dir.handle };
|
||||
const file: File = .{ .handle = dir.handle };
|
||||
return fileStat(t, file);
|
||||
}
|
||||
|
||||
|
|
@ -1615,10 +1617,10 @@ const dirStatPath = switch (native_os) {
|
|||
|
||||
fn dirStatPathLinux(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
options: Io.Dir.StatPathOptions,
|
||||
) Io.Dir.StatPathError!Io.File.Stat {
|
||||
options: Dir.StatPathOptions,
|
||||
) Dir.StatPathError!File.Stat {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
const linux = std.os.linux;
|
||||
|
|
@ -1670,10 +1672,10 @@ fn dirStatPathLinux(
|
|||
|
||||
fn dirStatPathPosix(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
options: Io.Dir.StatPathOptions,
|
||||
) Io.Dir.StatPathError!Io.File.Stat {
|
||||
options: Dir.StatPathOptions,
|
||||
) Dir.StatPathError!File.Stat {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -1718,10 +1720,10 @@ fn dirStatPathPosix(
|
|||
|
||||
fn dirStatPathWindows(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
options: Io.Dir.StatPathOptions,
|
||||
) Io.Dir.StatPathError!Io.File.Stat {
|
||||
options: Dir.StatPathOptions,
|
||||
) Dir.StatPathError!File.Stat {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const file = try dirOpenFileWindows(t, dir, sub_path, .{
|
||||
.follow_symlinks = options.follow_symlinks,
|
||||
|
|
@ -1732,10 +1734,10 @@ fn dirStatPathWindows(
|
|||
|
||||
fn dirStatPathWasi(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
options: Io.Dir.StatPathOptions,
|
||||
) Io.Dir.StatPathError!Io.File.Stat {
|
||||
options: Dir.StatPathOptions,
|
||||
) Dir.StatPathError!File.Stat {
|
||||
if (builtin.link_libc) return dirStatPathPosix(userdata, dir, sub_path, options);
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
|
@ -1783,7 +1785,7 @@ const fileStat = switch (native_os) {
|
|||
else => fileStatPosix,
|
||||
};
|
||||
|
||||
fn fileStatPosix(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.File.Stat {
|
||||
fn fileStatPosix(userdata: ?*anyopaque, file: File) File.StatError!File.Stat {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -1816,7 +1818,7 @@ fn fileStatPosix(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.File
|
|||
}
|
||||
}
|
||||
|
||||
fn fileStatLinux(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.File.Stat {
|
||||
fn fileStatLinux(userdata: ?*anyopaque, file: File) File.StatError!File.Stat {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
const linux = std.os.linux;
|
||||
|
|
@ -1860,7 +1862,7 @@ fn fileStatLinux(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.File
|
|||
}
|
||||
}
|
||||
|
||||
fn fileStatWindows(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.File.Stat {
|
||||
fn fileStatWindows(userdata: ?*anyopaque, file: File) File.StatError!File.Stat {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
try current_thread.checkCancel();
|
||||
|
|
@ -1908,7 +1910,7 @@ fn fileStatWindows(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.Fi
|
|||
};
|
||||
}
|
||||
|
||||
fn fileStatWasi(userdata: ?*anyopaque, file: Io.File) Io.File.StatError!Io.File.Stat {
|
||||
fn fileStatWasi(userdata: ?*anyopaque, file: File) File.StatError!File.Stat {
|
||||
if (builtin.link_libc) return fileStatPosix(userdata, file);
|
||||
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
|
|
@ -1950,10 +1952,10 @@ const dirAccess = switch (native_os) {
|
|||
|
||||
fn dirAccessPosix(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
options: Io.Dir.AccessOptions,
|
||||
) Io.Dir.AccessError!void {
|
||||
options: Dir.AccessOptions,
|
||||
) Dir.AccessError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -2004,10 +2006,10 @@ fn dirAccessPosix(
|
|||
|
||||
fn dirAccessWasi(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
options: Io.Dir.AccessOptions,
|
||||
) Io.Dir.AccessError!void {
|
||||
options: Dir.AccessOptions,
|
||||
) Dir.AccessError!void {
|
||||
if (builtin.link_libc) return dirAccessPosix(userdata, dir, sub_path, options);
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
|
@ -2077,10 +2079,10 @@ fn dirAccessWasi(
|
|||
|
||||
fn dirAccessWindows(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
options: Io.Dir.AccessOptions,
|
||||
) Io.Dir.AccessError!void {
|
||||
options: Dir.AccessOptions,
|
||||
) Dir.AccessError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
try current_thread.checkCancel();
|
||||
|
|
@ -2129,10 +2131,10 @@ const dirCreateFile = switch (native_os) {
|
|||
|
||||
fn dirCreateFilePosix(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
flags: Io.File.CreateFlags,
|
||||
) Io.File.OpenError!Io.File {
|
||||
flags: File.CreateFlags,
|
||||
) File.OpenError!File {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -2292,10 +2294,10 @@ fn dirCreateFilePosix(
|
|||
|
||||
fn dirCreateFileWindows(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
flags: Io.File.CreateFlags,
|
||||
) Io.File.OpenError!Io.File {
|
||||
flags: File.CreateFlags,
|
||||
) File.OpenError!File {
|
||||
const w = windows;
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
|
@ -2341,10 +2343,10 @@ fn dirCreateFileWindows(
|
|||
|
||||
fn dirCreateFileWasi(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
flags: Io.File.CreateFlags,
|
||||
) Io.File.OpenError!Io.File {
|
||||
flags: File.CreateFlags,
|
||||
) File.OpenError!File {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
const wasi = std.os.wasi;
|
||||
|
|
@ -2425,10 +2427,10 @@ const dirOpenFile = switch (native_os) {
|
|||
|
||||
fn dirOpenFilePosix(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
flags: Io.File.OpenFlags,
|
||||
) Io.File.OpenError!Io.File {
|
||||
flags: File.OpenFlags,
|
||||
) File.OpenError!File {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -2597,10 +2599,10 @@ fn dirOpenFilePosix(
|
|||
|
||||
fn dirOpenFileWindows(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
flags: Io.File.OpenFlags,
|
||||
) Io.File.OpenError!Io.File {
|
||||
flags: File.OpenFlags,
|
||||
) File.OpenError!File {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const sub_path_w_array = try windows.sliceToPrefixedFileW(dir.handle, sub_path);
|
||||
const sub_path_w = sub_path_w_array.span();
|
||||
|
|
@ -2612,8 +2614,8 @@ pub fn dirOpenFileWtf16(
|
|||
t: *Threaded,
|
||||
dir_handle: ?windows.HANDLE,
|
||||
sub_path_w: [:0]const u16,
|
||||
flags: Io.File.OpenFlags,
|
||||
) Io.File.OpenError!Io.File {
|
||||
flags: File.OpenFlags,
|
||||
) File.OpenError!File {
|
||||
if (std.mem.eql(u16, sub_path_w, &.{'.'})) return error.IsDir;
|
||||
if (std.mem.eql(u16, sub_path_w, &.{ '.', '.' })) return error.IsDir;
|
||||
const path_len_bytes = std.math.cast(u16, sub_path_w.len * 2) orelse return error.NameTooLong;
|
||||
|
|
@ -2734,10 +2736,10 @@ pub fn dirOpenFileWtf16(
|
|||
|
||||
fn dirOpenFileWasi(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
flags: Io.File.OpenFlags,
|
||||
) Io.File.OpenError!Io.File {
|
||||
flags: File.OpenFlags,
|
||||
) File.OpenError!File {
|
||||
if (builtin.link_libc) return dirOpenFilePosix(userdata, dir, sub_path, flags);
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
|
@ -2821,10 +2823,10 @@ const dirOpenDir = switch (native_os) {
|
|||
/// This function is also used for WASI when libc is linked.
|
||||
fn dirOpenDirPosix(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
options: Io.Dir.OpenOptions,
|
||||
) Io.Dir.OpenError!Io.Dir {
|
||||
options: Dir.OpenOptions,
|
||||
) Dir.OpenError!Dir {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
|
||||
if (is_windows) {
|
||||
|
|
@ -2895,10 +2897,10 @@ fn dirOpenDirPosix(
|
|||
|
||||
fn dirOpenDirHaiku(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
options: Io.Dir.OpenOptions,
|
||||
) Io.Dir.OpenError!Io.Dir {
|
||||
options: Dir.OpenOptions,
|
||||
) Dir.OpenError!Dir {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -2946,10 +2948,10 @@ fn dirOpenDirHaiku(
|
|||
|
||||
pub fn dirOpenDirWindows(
|
||||
t: *Io.Threaded,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path_w: [:0]const u16,
|
||||
options: Io.Dir.OpenOptions,
|
||||
) Io.Dir.OpenError!Io.Dir {
|
||||
options: Dir.OpenOptions,
|
||||
) Dir.OpenError!Dir {
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
const w = windows;
|
||||
// TODO remove some of these flags if options.access_sub_paths is false
|
||||
|
|
@ -2973,7 +2975,7 @@ pub fn dirOpenDirWindows(
|
|||
};
|
||||
const open_reparse_point: w.DWORD = if (!options.follow_symlinks) w.FILE_OPEN_REPARSE_POINT else 0x0;
|
||||
var io_status_block: w.IO_STATUS_BLOCK = undefined;
|
||||
var result: Io.Dir = .{ .handle = undefined };
|
||||
var result: Dir = .{ .handle = undefined };
|
||||
try current_thread.checkCancel();
|
||||
const rc = w.ntdll.NtCreateFile(
|
||||
&result.handle,
|
||||
|
|
@ -3009,7 +3011,7 @@ const MakeOpenDirAccessMaskWOptions = struct {
|
|||
create_disposition: u32,
|
||||
};
|
||||
|
||||
fn dirClose(userdata: ?*anyopaque, dir: Io.Dir) void {
|
||||
fn dirClose(userdata: ?*anyopaque, dir: Dir) void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
_ = t;
|
||||
posix.close(dir.handle);
|
||||
|
|
@ -3020,7 +3022,7 @@ const dirRealPath = switch (native_os) {
|
|||
else => dirRealPathPosix,
|
||||
};
|
||||
|
||||
fn dirRealPathWindows(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, out_buffer: []u8) Io.Dir.RealPathError!usize {
|
||||
fn dirRealPathWindows(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, out_buffer: []u8) Dir.RealPathError!usize {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const w = windows;
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
|
@ -3056,7 +3058,7 @@ fn dirRealPathWindows(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8,
|
|||
return std.unicode.wtf16LeToWtf8(out_buffer, wide_slice);
|
||||
}
|
||||
|
||||
fn dirRealPathPosix(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, out_buffer: []u8) Io.Dir.RealPathError!usize {
|
||||
fn dirRealPathPosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, out_buffer: []u8) Dir.RealPathError!usize {
|
||||
if (native_os == .wasi) @compileError("unsupported operating system");
|
||||
const max_path_bytes = std.fs.max_path_bytes;
|
||||
|
||||
|
|
@ -3253,11 +3255,11 @@ const dirDeleteFile = switch (native_os) {
|
|||
else => dirDeleteFilePosix,
|
||||
};
|
||||
|
||||
fn dirDeleteFileWindows(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8) Io.Dir.DeleteFileError!void {
|
||||
fn dirDeleteFileWindows(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8) Dir.DeleteFileError!void {
|
||||
return dirDeleteWindows(userdata, dir, sub_path, false);
|
||||
}
|
||||
|
||||
fn dirDeleteFileWasi(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8) Io.Dir.DeleteFileError!void {
|
||||
fn dirDeleteFileWasi(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8) Dir.DeleteFileError!void {
|
||||
if (builtin.link_libc) return dirDeleteFilePosix(userdata, dir, sub_path);
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
|
@ -3301,7 +3303,7 @@ fn dirDeleteFileWasi(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8) I
|
|||
}
|
||||
}
|
||||
|
||||
fn dirDeleteFilePosix(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8) Io.Dir.DeleteFileError!void {
|
||||
fn dirDeleteFilePosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8) Dir.DeleteFileError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -3386,11 +3388,11 @@ const dirDeleteDir = switch (native_os) {
|
|||
else => dirDeleteDirPosix,
|
||||
};
|
||||
|
||||
fn dirDeleteDirWindows(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8) Io.Dir.DeleteDirError!void {
|
||||
fn dirDeleteDirWindows(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8) Dir.DeleteDirError!void {
|
||||
return dirDeleteWindows(userdata, dir, sub_path, true);
|
||||
}
|
||||
|
||||
fn dirDeleteWindows(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, remove_dir: bool) Io.Dir.DeleteFileError!void {
|
||||
fn dirDeleteWindows(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, remove_dir: bool) Dir.DeleteFileError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
const w = windows;
|
||||
|
|
@ -3531,7 +3533,7 @@ fn dirDeleteWindows(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, re
|
|||
}
|
||||
}
|
||||
|
||||
fn dirDeleteDirWasi(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8) Io.Dir.DeleteDirError!void {
|
||||
fn dirDeleteDirWasi(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8) Dir.DeleteDirError!void {
|
||||
if (builtin.link_libc) return dirDeleteDirPosix(userdata, dir, sub_path);
|
||||
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
|
|
@ -3577,7 +3579,7 @@ fn dirDeleteDirWasi(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8) Io
|
|||
}
|
||||
}
|
||||
|
||||
fn dirDeleteDirPosix(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8) Io.Dir.DeleteDirError!void {
|
||||
fn dirDeleteDirPosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8) Dir.DeleteDirError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -3631,11 +3633,11 @@ const dirRename = switch (native_os) {
|
|||
|
||||
fn dirRenameWindows(
|
||||
userdata: ?*anyopaque,
|
||||
old_dir: Io.Dir,
|
||||
old_dir: Dir,
|
||||
old_sub_path: []const u8,
|
||||
new_dir: Io.Dir,
|
||||
new_dir: Dir,
|
||||
new_sub_path: []const u8,
|
||||
) Io.Dir.RenameError!void {
|
||||
) Dir.RenameError!void {
|
||||
const w = windows;
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
|
@ -3754,11 +3756,11 @@ fn dirRenameWindows(
|
|||
|
||||
fn dirRenameWasi(
|
||||
userdata: ?*anyopaque,
|
||||
old_dir: Io.Dir,
|
||||
old_dir: Dir,
|
||||
old_sub_path: []const u8,
|
||||
new_dir: Io.Dir,
|
||||
new_dir: Dir,
|
||||
new_sub_path: []const u8,
|
||||
) Io.Dir.RenameError!void {
|
||||
) Dir.RenameError!void {
|
||||
if (builtin.link_libc) return dirRenamePosix(userdata, old_dir, old_sub_path, new_dir, new_sub_path);
|
||||
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
|
|
@ -3805,11 +3807,11 @@ fn dirRenameWasi(
|
|||
|
||||
fn dirRenamePosix(
|
||||
userdata: ?*anyopaque,
|
||||
old_dir: Io.Dir,
|
||||
old_dir: Dir,
|
||||
old_sub_path: []const u8,
|
||||
new_dir: Io.Dir,
|
||||
new_dir: Dir,
|
||||
new_sub_path: []const u8,
|
||||
) Io.Dir.RenameError!void {
|
||||
) Dir.RenameError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -3865,11 +3867,11 @@ const dirSymLink = switch (native_os) {
|
|||
|
||||
fn dirSymLinkWindows(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
target_path: []const u8,
|
||||
sym_link_path: []const u8,
|
||||
flags: Io.Dir.SymLinkFlags,
|
||||
) Io.Dir.SymLinkError!void {
|
||||
flags: Dir.SymLinkFlags,
|
||||
) Dir.SymLinkError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
const w = windows;
|
||||
|
|
@ -3980,11 +3982,11 @@ fn dirSymLinkWindows(
|
|||
|
||||
fn dirSymLinkWasi(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
target_path: []const u8,
|
||||
sym_link_path: []const u8,
|
||||
flags: Io.Dir.SymLinkFlags,
|
||||
) Io.Dir.SymLinkError!void {
|
||||
flags: Dir.SymLinkFlags,
|
||||
) Dir.SymLinkError!void {
|
||||
if (builtin.link_libc) return dirSymLinkPosix(dir, target_path, sym_link_path, flags);
|
||||
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
|
|
@ -4028,11 +4030,11 @@ fn dirSymLinkWasi(
|
|||
|
||||
fn dirSymLinkPosix(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
target_path: []const u8,
|
||||
sym_link_path: []const u8,
|
||||
flags: Io.Dir.SymLinkFlags,
|
||||
) Io.Dir.SymLinkError!void {
|
||||
flags: Dir.SymLinkFlags,
|
||||
) Dir.SymLinkError!void {
|
||||
_ = flags;
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
|
@ -4083,7 +4085,7 @@ const dirReadLink = switch (native_os) {
|
|||
else => dirReadLinkPosix,
|
||||
};
|
||||
|
||||
fn dirReadLinkWindows(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, buffer: []u8) Io.Dir.ReadLinkError!usize {
|
||||
fn dirReadLinkWindows(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, buffer: []u8) Dir.ReadLinkError!usize {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
const w = windows;
|
||||
|
|
@ -4141,7 +4143,7 @@ fn dirReadLinkWindows(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8,
|
|||
return std.unicode.wtf16LeToWtf8(buffer, wide_result);
|
||||
}
|
||||
|
||||
fn dirReadLinkWasi(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, buffer: []u8) Io.Dir.ReadLinkError!usize {
|
||||
fn dirReadLinkWasi(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, buffer: []u8) Dir.ReadLinkError!usize {
|
||||
if (builtin.link_libc) return dirReadLinkPosix(userdata, dir, sub_path, buffer);
|
||||
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
|
|
@ -4181,7 +4183,7 @@ fn dirReadLinkWasi(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, buf
|
|||
}
|
||||
}
|
||||
|
||||
fn dirReadLinkPosix(userdata: ?*anyopaque, dir: Io.Dir, sub_path: []const u8, buffer: []u8) Io.Dir.ReadLinkError!usize {
|
||||
fn dirReadLinkPosix(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8, buffer: []u8) Dir.ReadLinkError!usize {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -4227,7 +4229,7 @@ const dirSetPermissions = switch (native_os) {
|
|||
else => dirSetPermissionsPosix,
|
||||
};
|
||||
|
||||
fn dirSetPermissionsWindows(userdata: ?*anyopaque, dir: Io.Dir, permissions: Io.Dir.Permissions) Io.Dir.SetPermissionsError!void {
|
||||
fn dirSetPermissionsWindows(userdata: ?*anyopaque, dir: Dir, permissions: Dir.Permissions) Dir.SetPermissionsError!void {
|
||||
// TODO I think we can actually set permissions on a dir on windows?
|
||||
_ = userdata;
|
||||
_ = dir;
|
||||
|
|
@ -4235,7 +4237,7 @@ fn dirSetPermissionsWindows(userdata: ?*anyopaque, dir: Io.Dir, permissions: Io.
|
|||
return error.Unexpected;
|
||||
}
|
||||
|
||||
fn dirSetPermissionsPosix(userdata: ?*anyopaque, dir: Io.Dir, permissions: Io.Dir.Permissions) Io.Dir.SetPermissionsError!void {
|
||||
fn dirSetPermissionsPosix(userdata: ?*anyopaque, dir: Dir, permissions: Dir.Permissions) Dir.SetPermissionsError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
return setPermissionsPosix(current_thread, dir.handle, permissions.toMode());
|
||||
|
|
@ -4246,7 +4248,7 @@ const dirSetOwner = switch (native_os) {
|
|||
else => dirSetOwnerPosix,
|
||||
};
|
||||
|
||||
fn dirSetOwnerUnsupported(userdata: ?*anyopaque, dir: Io.Dir, owner: ?Io.File.Uid, group: ?Io.File.Gid) Io.Dir.SetOwnerError!void {
|
||||
fn dirSetOwnerUnsupported(userdata: ?*anyopaque, dir: Dir, owner: ?File.Uid, group: ?File.Gid) Dir.SetOwnerError!void {
|
||||
_ = userdata;
|
||||
_ = dir;
|
||||
_ = owner;
|
||||
|
|
@ -4254,7 +4256,7 @@ fn dirSetOwnerUnsupported(userdata: ?*anyopaque, dir: Io.Dir, owner: ?Io.File.Ui
|
|||
return error.Unexpected;
|
||||
}
|
||||
|
||||
fn dirSetOwnerPosix(userdata: ?*anyopaque, dir: Io.Dir, owner: ?Io.File.Uid, group: ?Io.File.Gid) Io.Dir.SetOwnerError!void {
|
||||
fn dirSetOwnerPosix(userdata: ?*anyopaque, dir: Dir, owner: ?File.Uid, group: ?File.Gid) Dir.SetOwnerError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
const uid = owner orelse ~@as(posix.uid_t, 0);
|
||||
|
|
@ -4262,7 +4264,7 @@ fn dirSetOwnerPosix(userdata: ?*anyopaque, dir: Io.Dir, owner: ?Io.File.Uid, gro
|
|||
return setOwnerPosix(current_thread, dir.handle, uid, gid);
|
||||
}
|
||||
|
||||
fn setOwnerPosix(current_thread: *Thread, fd: posix.fd_t, uid: posix.uid_t, gid: posix.gid_t) Io.File.SetOwnerError!void {
|
||||
fn setOwnerPosix(current_thread: *Thread, fd: posix.fd_t, uid: posix.uid_t, gid: posix.gid_t) File.SetOwnerError!void {
|
||||
try current_thread.beginSyscall();
|
||||
while (true) {
|
||||
switch (posix.errno(posix.system.fchown(fd, uid, gid))) {
|
||||
|
|
@ -4275,7 +4277,7 @@ fn setOwnerPosix(current_thread: *Thread, fd: posix.fd_t, uid: posix.uid_t, gid:
|
|||
else => |e| {
|
||||
current_thread.endSyscall();
|
||||
switch (e) {
|
||||
.BADF => |err| return errnoBug(err), // likely fd refers to directory opened without `Io.Dir.OpenOptions.iterate`
|
||||
.BADF => |err| return errnoBug(err), // likely fd refers to directory opened without `Dir.OpenOptions.iterate`
|
||||
.FAULT => |err| return errnoBug(err),
|
||||
.INVAL => |err| return errnoBug(err),
|
||||
.ACCES => return error.AccessDenied,
|
||||
|
|
@ -4298,7 +4300,7 @@ const fileSync = switch (native_os) {
|
|||
else => fileSyncPosix,
|
||||
};
|
||||
|
||||
fn fileSyncWindows(userdata: ?*anyopaque, file: Io.File) Io.File.SyncError!void {
|
||||
fn fileSyncWindows(userdata: ?*anyopaque, file: File) File.SyncError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -4316,7 +4318,7 @@ fn fileSyncWindows(userdata: ?*anyopaque, file: Io.File) Io.File.SyncError!void
|
|||
}
|
||||
}
|
||||
|
||||
fn fileSyncPosix(userdata: ?*anyopaque, file: Io.File) Io.File.SyncError!void {
|
||||
fn fileSyncPosix(userdata: ?*anyopaque, file: File) File.SyncError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
try current_thread.beginSyscall();
|
||||
|
|
@ -4344,13 +4346,13 @@ fn fileSyncPosix(userdata: ?*anyopaque, file: Io.File) Io.File.SyncError!void {
|
|||
}
|
||||
}
|
||||
|
||||
fn fileIsTty(userdata: ?*anyopaque, file: Io.File) Io.Cancelable!bool {
|
||||
fn fileIsTty(userdata: ?*anyopaque, file: File) Io.Cancelable!bool {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
return isTty(current_thread, file);
|
||||
}
|
||||
|
||||
fn isTty(current_thread: *Thread, file: Io.File) Io.Cancelable!bool {
|
||||
fn isTty(current_thread: *Thread, file: File) Io.Cancelable!bool {
|
||||
if (is_windows) {
|
||||
if (try isCygwinPty(current_thread, file)) return true;
|
||||
try current_thread.checkCancel();
|
||||
|
|
@ -4423,7 +4425,7 @@ fn isTty(current_thread: *Thread, file: Io.File) Io.Cancelable!bool {
|
|||
@compileError("unimplemented");
|
||||
}
|
||||
|
||||
fn fileEnableAnsiEscapeCodes(userdata: ?*anyopaque, file: Io.File) Io.File.EnableAnsiEscapeCodesError!void {
|
||||
fn fileEnableAnsiEscapeCodes(userdata: ?*anyopaque, file: File) File.EnableAnsiEscapeCodesError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -4458,13 +4460,13 @@ fn fileEnableAnsiEscapeCodes(userdata: ?*anyopaque, file: Io.File) Io.File.Enabl
|
|||
return error.NotTerminalDevice;
|
||||
}
|
||||
|
||||
fn fileSupportsAnsiEscapeCodes(userdata: ?*anyopaque, file: Io.File) Io.Cancelable!bool {
|
||||
fn fileSupportsAnsiEscapeCodes(userdata: ?*anyopaque, file: File) Io.Cancelable!bool {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
return supportsAnsiEscapeCodes(current_thread, file);
|
||||
}
|
||||
|
||||
fn supportsAnsiEscapeCodes(current_thread: *Thread, file: Io.File) Io.Cancelable!bool {
|
||||
fn supportsAnsiEscapeCodes(current_thread: *Thread, file: File) Io.Cancelable!bool {
|
||||
if (is_windows) {
|
||||
try current_thread.checkCancel();
|
||||
var console_mode: windows.DWORD = 0;
|
||||
|
|
@ -4486,7 +4488,7 @@ fn supportsAnsiEscapeCodes(current_thread: *Thread, file: Io.File) Io.Cancelable
|
|||
return false;
|
||||
}
|
||||
|
||||
fn isCygwinPty(current_thread: *Thread, file: Io.File) Io.Cancelable!bool {
|
||||
fn isCygwinPty(current_thread: *Thread, file: File) Io.Cancelable!bool {
|
||||
if (!is_windows) return false;
|
||||
|
||||
const handle = file.handle;
|
||||
|
|
@ -4540,7 +4542,7 @@ fn isCygwinPty(current_thread: *Thread, file: Io.File) Io.Cancelable!bool {
|
|||
std.mem.indexOf(u16, name_wide, &[_]u16{ '-', 'p', 't', 'y' }) != null;
|
||||
}
|
||||
|
||||
fn fileSetLength(userdata: ?*anyopaque, file: Io.File, length: u64) Io.File.SetLengthError!void {
|
||||
fn fileSetLength(userdata: ?*anyopaque, file: File, length: u64) File.SetLengthError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -4624,7 +4626,7 @@ fn fileSetLength(userdata: ?*anyopaque, file: Io.File, length: u64) Io.File.SetL
|
|||
}
|
||||
}
|
||||
|
||||
fn fileSetOwner(userdata: ?*anyopaque, file: Io.File, owner: ?Io.File.Uid, group: ?Io.File.Gid) Io.File.SetOwnerError!void {
|
||||
fn fileSetOwner(userdata: ?*anyopaque, file: File, owner: ?File.Uid, group: ?File.Gid) File.SetOwnerError!void {
|
||||
switch (native_os) {
|
||||
.windows, .wasi => return error.Unexpected,
|
||||
else => {},
|
||||
|
|
@ -4636,7 +4638,7 @@ fn fileSetOwner(userdata: ?*anyopaque, file: Io.File, owner: ?Io.File.Uid, group
|
|||
return setOwnerPosix(current_thread, file.handle, uid, gid);
|
||||
}
|
||||
|
||||
fn fileSetPermissions(userdata: ?*anyopaque, file: Io.File, permissions: Io.File.Permissions) Io.File.SetPermissionsError!void {
|
||||
fn fileSetPermissions(userdata: ?*anyopaque, file: File, permissions: File.Permissions) File.SetPermissionsError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
switch (native_os) {
|
||||
|
|
@ -4669,7 +4671,7 @@ fn fileSetPermissions(userdata: ?*anyopaque, file: Io.File, permissions: Io.File
|
|||
}
|
||||
}
|
||||
|
||||
fn setPermissionsPosix(current_thread: *Thread, fd: posix.fd_t, mode: posix.mode_t) Io.File.SetPermissionsError!void {
|
||||
fn setPermissionsPosix(current_thread: *Thread, fd: posix.fd_t, mode: posix.mode_t) File.SetPermissionsError!void {
|
||||
try current_thread.beginSyscall();
|
||||
while (true) {
|
||||
switch (posix.errno(posix.system.fchmod(fd, mode))) {
|
||||
|
|
@ -4702,12 +4704,12 @@ fn setPermissionsPosix(current_thread: *Thread, fd: posix.fd_t, mode: posix.mode
|
|||
|
||||
fn dirSetTimestamps(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
last_accessed: Io.Timestamp,
|
||||
last_modified: Io.Timestamp,
|
||||
options: Io.File.SetTimestampsOptions,
|
||||
) Io.File.SetTimestampsError!void {
|
||||
options: File.SetTimestampsOptions,
|
||||
) File.SetTimestampsError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -4756,10 +4758,10 @@ fn dirSetTimestamps(
|
|||
|
||||
fn dirSetTimestampsNow(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
options: Io.File.SetTimestampsOptions,
|
||||
) Io.File.SetTimestampsError!void {
|
||||
options: File.SetTimestampsOptions,
|
||||
) File.SetTimestampsError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -4803,10 +4805,10 @@ fn dirSetTimestampsNow(
|
|||
|
||||
fn fileSetTimestamps(
|
||||
userdata: ?*anyopaque,
|
||||
file: Io.File,
|
||||
file: File,
|
||||
last_accessed: Io.Timestamp,
|
||||
last_modified: Io.Timestamp,
|
||||
) Io.File.SetTimestampsError!void {
|
||||
) File.SetTimestampsError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -4887,7 +4889,7 @@ fn fileSetTimestamps(
|
|||
}
|
||||
}
|
||||
|
||||
fn fileSetTimestampsNow(userdata: ?*anyopaque, file: Io.File) Io.File.SetTimestampsError!void {
|
||||
fn fileSetTimestampsNow(userdata: ?*anyopaque, file: File) File.SetTimestampsError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -4952,7 +4954,7 @@ fn fileSetTimestampsNow(userdata: ?*anyopaque, file: Io.File) Io.File.SetTimesta
|
|||
const windows_lock_range_off: windows.LARGE_INTEGER = 0;
|
||||
const windows_lock_range_len: windows.LARGE_INTEGER = 1;
|
||||
|
||||
fn fileLock(userdata: ?*anyopaque, file: Io.File, lock: Io.File.Lock) Io.File.LockError!void {
|
||||
fn fileLock(userdata: ?*anyopaque, file: File, lock: File.Lock) File.LockError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -5014,7 +5016,7 @@ fn fileLock(userdata: ?*anyopaque, file: Io.File, lock: Io.File.Lock) Io.File.Lo
|
|||
}
|
||||
}
|
||||
|
||||
fn fileTryLock(userdata: ?*anyopaque, file: Io.File, lock: Io.File.Lock) Io.File.LockError!bool {
|
||||
fn fileTryLock(userdata: ?*anyopaque, file: File, lock: File.Lock) File.LockError!bool {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -5082,7 +5084,7 @@ fn fileTryLock(userdata: ?*anyopaque, file: Io.File, lock: Io.File.Lock) Io.File
|
|||
}
|
||||
}
|
||||
|
||||
fn fileUnlock(userdata: ?*anyopaque, file: Io.File) void {
|
||||
fn fileUnlock(userdata: ?*anyopaque, file: File) void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -5130,7 +5132,7 @@ fn fileUnlock(userdata: ?*anyopaque, file: Io.File) void {
|
|||
}
|
||||
}
|
||||
|
||||
fn fileDowngradeLock(userdata: ?*anyopaque, file: Io.File) Io.File.DowngradeLockError!void {
|
||||
fn fileDowngradeLock(userdata: ?*anyopaque, file: File) File.DowngradeLockError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -5207,10 +5209,10 @@ fn fileDowngradeLock(userdata: ?*anyopaque, file: Io.File) Io.File.DowngradeLock
|
|||
|
||||
fn dirOpenDirWasi(
|
||||
userdata: ?*anyopaque,
|
||||
dir: Io.Dir,
|
||||
dir: Dir,
|
||||
sub_path: []const u8,
|
||||
options: Io.Dir.OpenOptions,
|
||||
) Io.Dir.OpenError!Io.Dir {
|
||||
options: Dir.OpenOptions,
|
||||
) Dir.OpenError!Dir {
|
||||
if (builtin.link_libc) return dirOpenDirPosix(userdata, dir, sub_path, options);
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
|
@ -5281,7 +5283,7 @@ fn dirOpenDirWasi(
|
|||
}
|
||||
}
|
||||
|
||||
fn fileClose(userdata: ?*anyopaque, file: Io.File) void {
|
||||
fn fileClose(userdata: ?*anyopaque, file: File) void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
_ = t;
|
||||
posix.close(file.handle);
|
||||
|
|
@ -5292,7 +5294,7 @@ const fileReadStreaming = switch (native_os) {
|
|||
else => fileReadStreamingPosix,
|
||||
};
|
||||
|
||||
fn fileReadStreamingPosix(userdata: ?*anyopaque, file: Io.File, data: [][]u8) Io.File.Reader.Error!usize {
|
||||
fn fileReadStreamingPosix(userdata: ?*anyopaque, file: File, data: [][]u8) File.Reader.Error!usize {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -5381,7 +5383,7 @@ fn fileReadStreamingPosix(userdata: ?*anyopaque, file: Io.File, data: [][]u8) Io
|
|||
}
|
||||
}
|
||||
|
||||
fn fileReadStreamingWindows(userdata: ?*anyopaque, file: Io.File, data: [][]u8) Io.File.Reader.Error!usize {
|
||||
fn fileReadStreamingWindows(userdata: ?*anyopaque, file: File, data: [][]u8) File.Reader.Error!usize {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -5410,7 +5412,7 @@ fn fileReadStreamingWindows(userdata: ?*anyopaque, file: Io.File, data: [][]u8)
|
|||
}
|
||||
}
|
||||
|
||||
fn fileReadPositionalPosix(userdata: ?*anyopaque, file: Io.File, data: [][]u8, offset: u64) Io.File.ReadPositionalError!usize {
|
||||
fn fileReadPositionalPosix(userdata: ?*anyopaque, file: File, data: [][]u8, offset: u64) File.ReadPositionalError!usize {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -5513,7 +5515,7 @@ const fileReadPositional = switch (native_os) {
|
|||
else => fileReadPositionalPosix,
|
||||
};
|
||||
|
||||
fn fileReadPositionalWindows(userdata: ?*anyopaque, file: Io.File, data: [][]u8, offset: u64) Io.File.ReadPositionalError!usize {
|
||||
fn fileReadPositionalWindows(userdata: ?*anyopaque, file: File, data: [][]u8, offset: u64) File.ReadPositionalError!usize {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -5555,7 +5557,7 @@ fn fileReadPositionalWindows(userdata: ?*anyopaque, file: Io.File, data: [][]u8,
|
|||
}
|
||||
}
|
||||
|
||||
fn fileSeekBy(userdata: ?*anyopaque, file: Io.File, offset: i64) Io.File.SeekError!void {
|
||||
fn fileSeekBy(userdata: ?*anyopaque, file: File, offset: i64) File.SeekError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
const fd = file.handle;
|
||||
|
|
@ -5653,7 +5655,7 @@ fn fileSeekBy(userdata: ?*anyopaque, file: Io.File, offset: i64) Io.File.SeekErr
|
|||
}
|
||||
}
|
||||
|
||||
fn fileSeekTo(userdata: ?*anyopaque, file: Io.File, offset: u64) Io.File.SeekError!void {
|
||||
fn fileSeekTo(userdata: ?*anyopaque, file: File, offset: u64) File.SeekError!void {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
const fd = file.handle;
|
||||
|
|
@ -5749,7 +5751,7 @@ fn fileSeekTo(userdata: ?*anyopaque, file: Io.File, offset: u64) Io.File.SeekErr
|
|||
}
|
||||
}
|
||||
|
||||
fn openSelfExe(userdata: ?*anyopaque, flags: Io.File.OpenFlags) Io.File.OpenSelfExeError!Io.File {
|
||||
fn openSelfExe(userdata: ?*anyopaque, flags: File.OpenFlags) File.OpenSelfExeError!File {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
switch (native_os) {
|
||||
.linux, .serenity => return dirOpenFilePosix(t, .{ .handle = posix.AT.FDCWD }, "/proc/self/exe", flags),
|
||||
|
|
@ -5768,12 +5770,12 @@ fn openSelfExe(userdata: ?*anyopaque, flags: Io.File.OpenFlags) Io.File.OpenSelf
|
|||
|
||||
fn fileWritePositional(
|
||||
userdata: ?*anyopaque,
|
||||
file: Io.File,
|
||||
file: File,
|
||||
header: []const u8,
|
||||
data: []const []const u8,
|
||||
splat: usize,
|
||||
offset: u64,
|
||||
) Io.File.WritePositionalError!usize {
|
||||
) File.WritePositionalError!usize {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -5890,11 +5892,11 @@ fn fileWritePositional(
|
|||
|
||||
fn fileWriteStreaming(
|
||||
userdata: ?*anyopaque,
|
||||
file: Io.File,
|
||||
file: File,
|
||||
header: []const u8,
|
||||
data: []const []const u8,
|
||||
splat: usize,
|
||||
) Io.File.WriteStreamingError!usize {
|
||||
) File.WriteStreamingError!usize {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const current_thread = Thread.getCurrent(t);
|
||||
|
||||
|
|
@ -6006,11 +6008,11 @@ fn fileWriteStreaming(
|
|||
|
||||
fn fileWriteFileStreaming(
|
||||
userdata: ?*anyopaque,
|
||||
file: Io.File,
|
||||
file: File,
|
||||
header: []const u8,
|
||||
file_reader: *Io.File.Reader,
|
||||
file_reader: *File.Reader,
|
||||
limit: Io.Limit,
|
||||
) Io.File.WriteFileStreamingError!usize {
|
||||
) File.WriteFileStreamingError!usize {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const reader_buffered = file_reader.interface.buffered();
|
||||
if (reader_buffered.len >= @intFromEnum(limit)) {
|
||||
|
|
@ -6404,7 +6406,7 @@ fn netWriteFile(
|
|||
userdata: ?*anyopaque,
|
||||
socket_handle: net.Socket.Handle,
|
||||
header: []const u8,
|
||||
file_reader: *Io.File.Reader,
|
||||
file_reader: *File.Reader,
|
||||
limit: Io.Limit,
|
||||
) net.Stream.WriteFileError!usize {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
|
|
@ -6418,12 +6420,12 @@ fn netWriteFile(
|
|||
|
||||
fn fileWriteFilePositional(
|
||||
userdata: ?*anyopaque,
|
||||
file: Io.File,
|
||||
file: File,
|
||||
header: []const u8,
|
||||
file_reader: *Io.File.Reader,
|
||||
file_reader: *File.Reader,
|
||||
limit: Io.Limit,
|
||||
offset: u64,
|
||||
) Io.File.WriteFilePositionalError!usize {
|
||||
) File.WriteFilePositionalError!usize {
|
||||
const t: *Threaded = @ptrCast(@alignCast(userdata));
|
||||
const reader_buffered = file_reader.interface.buffered();
|
||||
if (reader_buffered.len >= @intFromEnum(limit)) {
|
||||
|
|
@ -9304,7 +9306,7 @@ fn clockToWasi(clock: Io.Clock) std.os.wasi.clockid_t {
|
|||
};
|
||||
}
|
||||
|
||||
fn statFromLinux(stx: *const std.os.linux.Statx) Io.File.Stat {
|
||||
fn statFromLinux(stx: *const std.os.linux.Statx) File.Stat {
|
||||
const atime = stx.atime;
|
||||
const mtime = stx.mtime;
|
||||
const ctime = stx.ctime;
|
||||
|
|
@ -9328,7 +9330,7 @@ fn statFromLinux(stx: *const std.os.linux.Statx) Io.File.Stat {
|
|||
};
|
||||
}
|
||||
|
||||
fn statFromPosix(st: *const posix.Stat) Io.File.Stat {
|
||||
fn statFromPosix(st: *const posix.Stat) File.Stat {
|
||||
const atime = st.atime();
|
||||
const mtime = st.mtime();
|
||||
const ctime = st.ctime();
|
||||
|
|
@ -9362,7 +9364,7 @@ fn statFromPosix(st: *const posix.Stat) Io.File.Stat {
|
|||
};
|
||||
}
|
||||
|
||||
fn statFromWasi(st: *const std.os.wasi.filestat_t) Io.File.Stat {
|
||||
fn statFromWasi(st: *const std.os.wasi.filestat_t) File.Stat {
|
||||
return .{
|
||||
.inode = st.ino,
|
||||
.size = @bitCast(st.size),
|
||||
|
|
@ -9393,7 +9395,7 @@ fn timestampToPosix(nanoseconds: i96) posix.timespec {
|
|||
};
|
||||
}
|
||||
|
||||
fn pathToPosix(file_path: []const u8, buffer: *[posix.PATH_MAX]u8) Io.Dir.PathNameError![:0]u8 {
|
||||
fn pathToPosix(file_path: []const u8, buffer: *[posix.PATH_MAX]u8) Dir.PathNameError![:0]u8 {
|
||||
if (std.mem.containsAtLeastScalar2(u8, file_path, 0, 1)) return error.BadPathName;
|
||||
// >= rather than > to make room for the null byte
|
||||
if (file_path.len >= buffer.len) return error.NameTooLong;
|
||||
|
|
@ -9640,7 +9642,7 @@ fn lookupHosts(
|
|||
options: HostName.LookupOptions,
|
||||
) !void {
|
||||
const t_io = io(t);
|
||||
const file = Io.File.openAbsolute(t_io, "/etc/hosts", .{}) catch |err| switch (err) {
|
||||
const file = File.openAbsolute(t_io, "/etc/hosts", .{}) catch |err| switch (err) {
|
||||
error.FileNotFound,
|
||||
error.NotDir,
|
||||
error.AccessDenied,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue