posix read can return error.IsDir

This commit is contained in:
Andrew Kelley 2018-06-16 19:54:16 -04:00
parent eae9634ac9
commit 3ee4d23ebd
2 changed files with 10 additions and 2 deletions

View File

@ -639,6 +639,7 @@ const ParseFormValueError = error{
Unexpected,
InvalidDebugInfo,
EndOfFile,
IsDir,
OutOfMemory,
};

View File

@ -311,9 +311,15 @@ pub const File = struct {
}
}
pub const ReadError = error{};
pub const ReadError = error{
BadFd,
Io,
IsDir,
pub fn read(self: *File, buffer: []u8) !usize {
Unexpected,
};
pub fn read(self: *File, buffer: []u8) ReadError!usize {
if (is_posix) {
var index: usize = 0;
while (index < buffer.len) {
@ -326,6 +332,7 @@ pub const File = struct {
posix.EFAULT => unreachable,
posix.EBADF => return error.BadFd,
posix.EIO => return error.Io,
posix.EISDIR => return error.IsDir,
else => return os.unexpectedErrorPosix(read_err),
}
}