mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
std.fs.Dir.openFile: use wasi libc API when -lc
Also removes the LOCK namespace from std.c.wasi because wasi libc does not have flock. closes #19336 related to #19352 Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
This commit is contained in:
parent
3c221463fd
commit
d06e5b4349
@ -40,12 +40,6 @@ pub const E = wasi.errno_t;
|
||||
|
||||
pub const CLOCK = wasi.clockid_t;
|
||||
pub const IOV_MAX = 1024;
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 0x1;
|
||||
pub const EX = 0x2;
|
||||
pub const NB = 0x4;
|
||||
pub const UN = 0x8;
|
||||
};
|
||||
pub const S = struct {
|
||||
pub const IEXEC = @compileError("TODO audit this");
|
||||
pub const IFBLK = 0x6000;
|
||||
|
||||
@ -800,7 +800,7 @@ pub fn openFile(self: Dir, sub_path: []const u8, flags: File.OpenFlags) File.Ope
|
||||
const path_w = try windows.sliceToPrefixedFileW(self.fd, sub_path);
|
||||
return self.openFileW(path_w.span(), flags);
|
||||
}
|
||||
if (native_os == .wasi) {
|
||||
if (native_os == .wasi and !builtin.link_libc) {
|
||||
var base: std.os.wasi.rights_t = .{};
|
||||
if (flags.isRead()) {
|
||||
base.FD_READ = true;
|
||||
@ -834,17 +834,25 @@ pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File
|
||||
const path_w = try windows.cStrToPrefixedFileW(self.fd, sub_path);
|
||||
return self.openFileW(path_w.span(), flags);
|
||||
},
|
||||
.wasi => {
|
||||
// Use the libc API when libc is linked because it implements things
|
||||
// such as opening absolute file paths.
|
||||
.wasi => if (!builtin.link_libc) {
|
||||
return openFile(self, mem.sliceTo(sub_path, 0), flags);
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
|
||||
var os_flags: posix.O = .{
|
||||
.ACCMODE = switch (flags.mode) {
|
||||
.read_only => .RDONLY,
|
||||
.write_only => .WRONLY,
|
||||
.read_write => .RDWR,
|
||||
var os_flags: posix.O = switch (native_os) {
|
||||
.wasi => .{
|
||||
.read = flags.mode != .write_only,
|
||||
.write = flags.mode != .read_only,
|
||||
},
|
||||
else => .{
|
||||
.ACCMODE = switch (flags.mode) {
|
||||
.read_only => .RDONLY,
|
||||
.write_only => .WRONLY,
|
||||
.read_write => .RDWR,
|
||||
},
|
||||
},
|
||||
};
|
||||
if (@hasField(posix.O, "CLOEXEC")) os_flags.CLOEXEC = true;
|
||||
|
||||
@ -1602,6 +1602,10 @@ pub fn openZ(file_path: [*:0]const u8, flags: O, perm: mode_t) OpenError!fd_t {
|
||||
.PERM => return error.AccessDenied,
|
||||
.EXIST => return error.PathAlreadyExists,
|
||||
.BUSY => return error.DeviceBusy,
|
||||
.ILSEQ => |err| if (native_os == .wasi)
|
||||
return error.InvalidUtf8
|
||||
else
|
||||
return unexpectedErrno(err),
|
||||
else => |err| return unexpectedErrno(err),
|
||||
}
|
||||
}
|
||||
@ -1771,6 +1775,10 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: O, mode: mode_t) O
|
||||
.OPNOTSUPP => return error.FileLocksNotSupported,
|
||||
.AGAIN => return error.WouldBlock,
|
||||
.TXTBSY => return error.FileBusy,
|
||||
.ILSEQ => |err| if (native_os == .wasi)
|
||||
return error.InvalidUtf8
|
||||
else
|
||||
return unexpectedErrno(err),
|
||||
else => |err| return unexpectedErrno(err),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user