Commit 55e879d2ed

Jan Philipp Hafer <jan.hafer@rwth-aachen.de>
2022-12-06 22:21:23
std.os.windows: add possible error NETNAME_DELETED of ReadFile
Closes #13631
1 parent 3cb1ab0
Changed files (5)
lib/std/os/windows.zig
@@ -435,8 +435,9 @@ pub fn FindClose(hFindFile: HANDLE) void {
 }
 
 pub const ReadFileError = error{
-    OperationAborted,
     BrokenPipe,
+    NetNameDeleted,
+    OperationAborted,
     Unexpected,
 };
 
@@ -475,6 +476,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo
                 .IO_PENDING => unreachable,
                 .OPERATION_ABORTED => return error.OperationAborted,
                 .BROKEN_PIPE => return error.BrokenPipe,
+                .NETNAME_DELETED => return error.NetNameDeleted,
                 .HANDLE_EOF => return @as(usize, bytes_transferred),
                 else => |err| return unexpectedError(err),
             }
@@ -506,9 +508,11 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64, io_mode: std.io.Mo
             } else null;
             if (kernel32.ReadFile(in_hFile, buffer.ptr, want_read_count, &amt_read, overlapped) == 0) {
                 switch (kernel32.GetLastError()) {
+                    .IO_PENDING => unreachable,
                     .OPERATION_ABORTED => continue,
                     .BROKEN_PIPE => return 0,
                     .HANDLE_EOF => return 0,
+                    .NETNAME_DELETED => return error.NetNameDeleted,
                     else => |err| return unexpectedError(err),
                 }
             }
lib/std/zig/system/NativeTargetInfo.zig
@@ -917,6 +917,7 @@ fn preadMin(file: fs.File, buf: []u8, offset: u64, min_read_len: usize) !usize {
             error.Unseekable => return error.UnableToReadElfFile,
             error.ConnectionResetByPeer => return error.UnableToReadElfFile,
             error.ConnectionTimedOut => return error.UnableToReadElfFile,
+            error.NetNameDeleted => return error.UnableToReadElfFile,
             error.Unexpected => return error.Unexpected,
             error.InputOutput => return error.FileSystem,
             error.AccessDenied => return error.Unexpected,
lib/std/os.zig
@@ -641,6 +641,9 @@ pub const ReadError = error{
     ConnectionTimedOut,
     NotOpenForReading,
 
+    // Windows only
+    NetNameDeleted,
+
     /// This error occurs when no global event loop is configured,
     /// and reading from the file descriptor would block.
     WouldBlock,
src/link.zig
@@ -489,6 +489,7 @@ pub const File = struct {
         NameTooLong,
         CurrentWorkingDirectoryUnlinked,
         LockViolation,
+        NetNameDeleted,
     };
 
     /// Called from within the CodeGen to lower a local variable instantion as an unnamed
src/main.zig
@@ -4482,6 +4482,7 @@ const FmtError = error{
     UnsupportedEncoding,
     ConnectionResetByPeer,
     LockViolation,
+    NetNameDeleted,
 } || fs.File.OpenError;
 
 fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool, dir: fs.Dir, sub_path: []const u8) FmtError!void {