std.Io.Threaded: fix EBADF error code on wasm32-wasi -lc when reading

This commit is contained in:
Andrew Kelley 2025-10-28 07:11:52 -07:00
parent c4dc7d7c3d
commit 030b630829

View File

@ -2253,6 +2253,7 @@ const dirOpenDir = switch (native_os) {
else => dirOpenDirPosix, else => dirOpenDirPosix,
}; };
/// This function is also used for WASI when libc is linked.
fn dirOpenDirPosix( fn dirOpenDirPosix(
userdata: ?*anyopaque, userdata: ?*anyopaque,
dir: Io.Dir, dir: Io.Dir,
@ -2551,7 +2552,10 @@ fn fileReadStreamingPosix(userdata: ?*anyopaque, file: Io.File, data: [][]u8) Io
.FAULT => |err| return errnoBug(err), .FAULT => |err| return errnoBug(err),
.SRCH => return error.ProcessNotFound, .SRCH => return error.ProcessNotFound,
.AGAIN => return error.WouldBlock, .AGAIN => return error.WouldBlock,
.BADF => |err| return errnoBug(err), // File descriptor used after closed. .BADF => |err| {
if (native_os == .wasi) return error.NotOpenForReading; // File operation on directory.
return errnoBug(err); // File descriptor used after closed.
},
.IO => return error.InputOutput, .IO => return error.InputOutput,
.ISDIR => return error.IsDir, .ISDIR => return error.IsDir,
.NOBUFS => return error.SystemResources, .NOBUFS => return error.SystemResources,
@ -2648,7 +2652,10 @@ fn fileReadPositionalPosix(userdata: ?*anyopaque, file: Io.File, data: [][]u8, o
.FAULT => |err| return errnoBug(err), .FAULT => |err| return errnoBug(err),
.SRCH => return error.ProcessNotFound, .SRCH => return error.ProcessNotFound,
.AGAIN => return error.WouldBlock, .AGAIN => return error.WouldBlock,
.BADF => |err| return errnoBug(err), // File descriptor used after closed. .BADF => |err| {
if (native_os == .wasi) return error.NotOpenForReading; // File operation on directory.
return errnoBug(err); // File descriptor used after closed.
},
.IO => return error.InputOutput, .IO => return error.InputOutput,
.ISDIR => return error.IsDir, .ISDIR => return error.IsDir,
.NOBUFS => return error.SystemResources, .NOBUFS => return error.SystemResources,