authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-13 19:04:02-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:49-07:00
logd680b9e9b2320612a4e988763f5090c4ae8f9a8f
tree27fa5132572250a2c2093f2b3ea3772290721d44
parent539808239ecae050e383dd11f395a363b4404e21

std.Io.File: add WouldBlock to the error set

Even in an asynchronous world, the concept of a non-blocking flag is useful because it determines under what conditions the operation completes.

2 files changed, 6 insertions(+), 4 deletions(-)

lib/std/Io/File.zig+2
...@@ -139,6 +139,8 @@ pub const OpenError = error{...@@ -139,6 +139,8 @@ pub const OpenError = error{
139 /// kernel (e.g., for module/firmware loading), and write access was139 /// kernel (e.g., for module/firmware loading), and write access was
140 /// requested.140 /// requested.
141 FileBusy,141 FileBusy,
142 /// Non-blocking was requested and the operation cannot return immediately.
143 WouldBlock,
142} || Io.Dir.PathNameError || Io.Cancelable || Io.UnexpectedError;144} || Io.Dir.PathNameError || Io.Cancelable || Io.UnexpectedError;
143145
144pub fn close(file: File, io: Io) void {146pub fn close(file: File, io: Io) void {
lib/std/Io/Threaded.zig+4-4
...@@ -1039,7 +1039,7 @@ fn dirCreateFilePosix(...@@ -1039,7 +1039,7 @@ fn dirCreateFilePosix(
1039 .EXIST => return error.PathAlreadyExists,1039 .EXIST => return error.PathAlreadyExists,
1040 .BUSY => return error.DeviceBusy,1040 .BUSY => return error.DeviceBusy,
1041 .OPNOTSUPP => return error.FileLocksNotSupported,1041 .OPNOTSUPP => return error.FileLocksNotSupported,
1042 //.AGAIN => return error.WouldBlock,1042 .AGAIN => return error.WouldBlock,
1043 .TXTBSY => return error.FileBusy,1043 .TXTBSY => return error.FileBusy,
1044 .NXIO => return error.NoDevice,1044 .NXIO => return error.NoDevice,
1045 .ILSEQ => return error.BadPathName,1045 .ILSEQ => return error.BadPathName,
...@@ -1064,7 +1064,7 @@ fn dirCreateFilePosix(...@@ -1064,7 +1064,7 @@ fn dirCreateFilePosix(
1064 .BADF => |err| return errnoBug(err),1064 .BADF => |err| return errnoBug(err),
1065 .INVAL => |err| return errnoBug(err), // invalid parameters1065 .INVAL => |err| return errnoBug(err), // invalid parameters
1066 .NOLCK => return error.SystemResources,1066 .NOLCK => return error.SystemResources,
1067 //.AGAIN => return error.WouldBlock,1067 .AGAIN => return error.WouldBlock,
1068 .OPNOTSUPP => return error.FileLocksNotSupported,1068 .OPNOTSUPP => return error.FileLocksNotSupported,
1069 else => |err| return posix.unexpectedErrno(err),1069 else => |err| return posix.unexpectedErrno(err),
1070 }1070 }
...@@ -1168,7 +1168,7 @@ fn dirOpenFile(...@@ -1168,7 +1168,7 @@ fn dirOpenFile(
1168 .EXIST => return error.PathAlreadyExists,1168 .EXIST => return error.PathAlreadyExists,
1169 .BUSY => return error.DeviceBusy,1169 .BUSY => return error.DeviceBusy,
1170 .OPNOTSUPP => return error.FileLocksNotSupported,1170 .OPNOTSUPP => return error.FileLocksNotSupported,
1171 //.AGAIN => return error.WouldBlock,1171 .AGAIN => return error.WouldBlock,
1172 .TXTBSY => return error.FileBusy,1172 .TXTBSY => return error.FileBusy,
1173 .NXIO => return error.NoDevice,1173 .NXIO => return error.NoDevice,
1174 .ILSEQ => return error.BadPathName,1174 .ILSEQ => return error.BadPathName,
...@@ -1193,7 +1193,7 @@ fn dirOpenFile(...@@ -1193,7 +1193,7 @@ fn dirOpenFile(
1193 .BADF => |err| return errnoBug(err),1193 .BADF => |err| return errnoBug(err),
1194 .INVAL => |err| return errnoBug(err), // invalid parameters1194 .INVAL => |err| return errnoBug(err), // invalid parameters
1195 .NOLCK => return error.SystemResources,1195 .NOLCK => return error.SystemResources,
1196 //.AGAIN => return error.WouldBlock,1196 .AGAIN => return error.WouldBlock,
1197 .OPNOTSUPP => return error.FileLocksNotSupported,1197 .OPNOTSUPP => return error.FileLocksNotSupported,
1198 else => |err| return posix.unexpectedErrno(err),1198 else => |err| return posix.unexpectedErrno(err),
1199 }1199 }