diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-08-19 23:46:22 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-08-19 23:46:22 -0400 |
| commit | b1c7334355b345a6c244f617c2d4fae9e9f82c5a (patch) | |
| tree | c97071917e07990ef415e4bd948c0f3c08c4141c /lib/std/os.zig | |
| parent | a30950706f858e052376fb2d526895970f59d0ca (diff) | |
| parent | e2cfc65909d49d1102fa440759f5475ced0c0c15 (diff) | |
| download | zig-b1c7334355b345a6c244f617c2d4fae9e9f82c5a.tar.gz zig-b1c7334355b345a6c244f617c2d4fae9e9f82c5a.zip | |
Merge pull request #5745 from lun-4/ebadf-error
map EBADF to error values for read and write
Diffstat (limited to 'lib/std/os.zig')
| -rw-r--r-- | lib/std/os.zig | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig index 828f056148..6f58d7f077 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -296,6 +296,7 @@ pub const ReadError = error{ BrokenPipe, ConnectionResetByPeer, ConnectionTimedOut, + NotOpenForReading, /// This error occurs when no global event loop is configured, /// and reading from the file descriptor would block. @@ -332,7 +333,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize { wasi.EINVAL => unreachable, wasi.EFAULT => unreachable, wasi.EAGAIN => unreachable, - wasi.EBADF => unreachable, // Always a race condition. + wasi.EBADF => return error.NotOpenForReading, // Can be a race condition. wasi.EIO => return error.InputOutput, wasi.EISDIR => return error.IsDir, wasi.ENOBUFS => return error.SystemResources, @@ -364,7 +365,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize { } else { return error.WouldBlock; }, - EBADF => unreachable, // Always a race condition. + EBADF => return error.NotOpenForReading, // Can be a race condition. EIO => return error.InputOutput, EISDIR => return error.IsDir, ENOBUFS => return error.SystemResources, @@ -402,7 +403,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize { wasi.EINVAL => unreachable, wasi.EFAULT => unreachable, wasi.EAGAIN => unreachable, // currently not support in WASI - wasi.EBADF => unreachable, // always a race condition + wasi.EBADF => return error.NotOpenForReading, // can be a race condition wasi.EIO => return error.InputOutput, wasi.EISDIR => return error.IsDir, wasi.ENOBUFS => return error.SystemResources, @@ -426,7 +427,7 @@ pub fn readv(fd: fd_t, iov: []const iovec) ReadError!usize { } else { return error.WouldBlock; }, - EBADF => unreachable, // always a race condition + EBADF => return error.NotOpenForReading, // can be a race condition EIO => return error.InputOutput, EISDIR => return error.IsDir, ENOBUFS => return error.SystemResources, @@ -463,7 +464,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize { wasi.EINVAL => unreachable, wasi.EFAULT => unreachable, wasi.EAGAIN => unreachable, - wasi.EBADF => unreachable, // Always a race condition. + wasi.EBADF => return error.NotOpenForReading, // Can be a race condition. wasi.EIO => return error.InputOutput, wasi.EISDIR => return error.IsDir, wasi.ENOBUFS => return error.SystemResources, @@ -490,7 +491,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize { } else { return error.WouldBlock; }, - EBADF => unreachable, // Always a race condition. + EBADF => return error.NotOpenForReading, // Can be a race condition. EIO => return error.InputOutput, EISDIR => return error.IsDir, ENOBUFS => return error.SystemResources, @@ -607,7 +608,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize { wasi.EINVAL => unreachable, wasi.EFAULT => unreachable, wasi.EAGAIN => unreachable, - wasi.EBADF => unreachable, // always a race condition + wasi.EBADF => return error.NotOpenForReading, // can be a race condition wasi.EIO => return error.InputOutput, wasi.EISDIR => return error.IsDir, wasi.ENOBUFS => return error.SystemResources, @@ -635,7 +636,7 @@ pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) PReadError!usize { } else { return error.WouldBlock; }, - EBADF => unreachable, // always a race condition + EBADF => return error.NotOpenForReading, // can be a race condition EIO => return error.InputOutput, EISDIR => return error.IsDir, ENOBUFS => return error.SystemResources, @@ -660,6 +661,7 @@ pub const WriteError = error{ BrokenPipe, SystemResources, OperationAborted, + NotOpenForWriting, /// This error occurs when no global event loop is configured, /// and reading from the file descriptor would block. @@ -704,7 +706,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize { wasi.EINVAL => unreachable, wasi.EFAULT => unreachable, wasi.EAGAIN => unreachable, - wasi.EBADF => unreachable, // Always a race condition. + wasi.EBADF => return error.NotOpenForWriting, // can be a race condition. wasi.EDESTADDRREQ => unreachable, // `connect` was never called. wasi.EDQUOT => return error.DiskQuota, wasi.EFBIG => return error.FileTooBig, @@ -736,7 +738,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize { } else { return error.WouldBlock; }, - EBADF => unreachable, // Always a race condition. + EBADF => return error.NotOpenForWriting, // can be a race condition. EDESTADDRREQ => unreachable, // `connect` was never called. EDQUOT => return error.DiskQuota, EFBIG => return error.FileTooBig, @@ -782,7 +784,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize { wasi.EINVAL => unreachable, wasi.EFAULT => unreachable, wasi.EAGAIN => unreachable, - wasi.EBADF => unreachable, // Always a race condition. + wasi.EBADF => return error.NotOpenForWriting, // can be a race condition. wasi.EDESTADDRREQ => unreachable, // `connect` was never called. wasi.EDQUOT => return error.DiskQuota, wasi.EFBIG => return error.FileTooBig, @@ -809,7 +811,7 @@ pub fn writev(fd: fd_t, iov: []const iovec_const) WriteError!usize { } else { return error.WouldBlock; }, - EBADF => unreachable, // Always a race condition. + EBADF => return error.NotOpenForWriting, // Can be a race condition. EDESTADDRREQ => unreachable, // `connect` was never called. EDQUOT => return error.DiskQuota, EFBIG => return error.FileTooBig, @@ -862,7 +864,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize { wasi.EINVAL => unreachable, wasi.EFAULT => unreachable, wasi.EAGAIN => unreachable, - wasi.EBADF => unreachable, // Always a race condition. + wasi.EBADF => return error.NotOpenForWriting, // can be a race condition. wasi.EDESTADDRREQ => unreachable, // `connect` was never called. wasi.EDQUOT => return error.DiskQuota, wasi.EFBIG => return error.FileTooBig, @@ -898,7 +900,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize { } else { return error.WouldBlock; }, - EBADF => unreachable, // Always a race condition. + EBADF => return error.NotOpenForWriting, // Can be a race condition. EDESTADDRREQ => unreachable, // `connect` was never called. EDQUOT => return error.DiskQuota, EFBIG => return error.FileTooBig, @@ -956,7 +958,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz wasi.EINVAL => unreachable, wasi.EFAULT => unreachable, wasi.EAGAIN => unreachable, - wasi.EBADF => unreachable, // Always a race condition. + wasi.EBADF => return error.NotOpenForWriting, // Can be a race condition. wasi.EDESTADDRREQ => unreachable, // `connect` was never called. wasi.EDQUOT => return error.DiskQuota, wasi.EFBIG => return error.FileTooBig, @@ -986,7 +988,7 @@ pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usiz } else { return error.WouldBlock; }, - EBADF => unreachable, // Always a race condition. + EBADF => return error.NotOpenForWriting, // Can be a race condition. EDESTADDRREQ => unreachable, // `connect` was never called. EDQUOT => return error.DiskQuota, EFBIG => return error.FileTooBig, @@ -1251,7 +1253,7 @@ pub fn dup2(old_fd: fd_t, new_fd: fd_t) !void { EBUSY, EINTR => continue, EMFILE => return error.ProcessFdQuotaExceeded, EINVAL => unreachable, // invalid parameters passed to dup2 - EBADF => unreachable, // always a race condition + EBADF => unreachable, // invalid file descriptor else => |err| return unexpectedErrno(err), } } |
