authorgravatar for 178673413+psbob@users.noreply.github.compsbob <178673413+psbob@users.noreply.github.com> 2025-04-27 15:42:15+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-04-27 14:42:15+00:00
logd92649da80a526f2e2b2f220c05b81becf4fa627
tree36620fa425c5dbb0071b451df8c191f27849b495
parentb16c094926cf659e144cbcbed6c69cd820c5ff9f
signaturebadge-check Signed by PGP key B5690EEEBB952194

Update Windows ReadFile and WriteFile to recognise Access Denied error when a read or write is attempted on a disconnected virtual com port


1 files changed, 8 insertions(+), 0 deletions(-)

lib/std/os/windows.zig+8
...@@ -602,6 +602,9 @@ pub const ReadFileError = error{...@@ -602,6 +602,9 @@ pub const ReadFileError = error{
602 OperationAborted,602 OperationAborted,
603 /// Unable to read file due to lock.603 /// Unable to read file due to lock.
604 LockViolation,604 LockViolation,
605 /// Known to be possible when:
606 /// - Unable to read from disconnected virtual com port (Windows)
607 AccessDenied,
605 Unexpected,608 Unexpected,
606};609};
607610
...@@ -634,6 +637,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64) ReadFileError!usiz...@@ -634,6 +637,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8, offset: ?u64) ReadFileError!usiz
634 .HANDLE_EOF => return 0,637 .HANDLE_EOF => return 0,
635 .NETNAME_DELETED => return error.ConnectionResetByPeer,638 .NETNAME_DELETED => return error.ConnectionResetByPeer,
636 .LOCK_VIOLATION => return error.LockViolation,639 .LOCK_VIOLATION => return error.LockViolation,
640 .ACCESS_DENIED => return error.AccessDenied,
637 else => |err| return unexpectedError(err),641 else => |err| return unexpectedError(err),
638 }642 }
639 }643 }
...@@ -651,6 +655,9 @@ pub const WriteFileError = error{...@@ -651,6 +655,9 @@ pub const WriteFileError = error{
651 LockViolation,655 LockViolation,
652 /// The specified network name is no longer available.656 /// The specified network name is no longer available.
653 ConnectionResetByPeer,657 ConnectionResetByPeer,
658 /// Known to be possible when:
659 /// - Unable to write to disconnected virtual com port (Windows)
660 AccessDenied,
654 Unexpected,661 Unexpected,
655};662};
656663
...@@ -687,6 +694,7 @@ pub fn WriteFile(...@@ -687,6 +694,7 @@ pub fn WriteFile(
687 .INVALID_HANDLE => return error.NotOpenForWriting,694 .INVALID_HANDLE => return error.NotOpenForWriting,
688 .LOCK_VIOLATION => return error.LockViolation,695 .LOCK_VIOLATION => return error.LockViolation,
689 .NETNAME_DELETED => return error.ConnectionResetByPeer,696 .NETNAME_DELETED => return error.ConnectionResetByPeer,
697 .ACCESS_DENIED => return error.AccessDenied,
690 else => |err| return unexpectedError(err),698 else => |err| return unexpectedError(err),
691 }699 }
692 }700 }