diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-05 18:34:28 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-05 18:36:13 +0200 |
commit | a9204510a4c0c37588a38201f305d7e9b4e762a9 (patch) | |
tree | 752b1077191f2608755104f6cca2a19bc9f4591c /Kernel/Syscalls/read.cpp | |
parent | 2d2ea05c97e97848f431b5c9e5f709fe276eb7c8 (diff) | |
download | serenity-a9204510a4c0c37588a38201f305d7e9b4e762a9.zip |
Kernel: Make file description lookup return KResultOr
Instead of checking it at every call site (to generate EBADF), we make
file_description(fd) return a KResultOr<NonnullRefPtr<FileDescription>>.
This allows us to wrap all the calls in TRY(). :^)
The only place that got a little bit messier from this is sys$mount(),
and there's a whole bunch of things there in need of cleanup.
Diffstat (limited to 'Kernel/Syscalls/read.cpp')
-rw-r--r-- | Kernel/Syscalls/read.cpp | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/Kernel/Syscalls/read.cpp b/Kernel/Syscalls/read.cpp index 19bb1e1db8..99308cbab5 100644 --- a/Kernel/Syscalls/read.cpp +++ b/Kernel/Syscalls/read.cpp @@ -34,13 +34,9 @@ KResultOr<FlatPtr> Process::sys$readv(int fd, Userspace<const struct iovec*> iov return EINVAL; } - auto description = fds().file_description(fd); - if (!description) - return EBADF; - + auto description = TRY(fds().file_description(fd)); if (!description->is_readable()) return EBADF; - if (description->is_directory()) return EISDIR; @@ -75,9 +71,7 @@ KResultOr<FlatPtr> Process::sys$read(int fd, Userspace<u8*> buffer, size_t size) if (size > NumericLimits<ssize_t>::max()) return EINVAL; dbgln_if(IO_DEBUG, "sys$read({}, {}, {})", fd, buffer.ptr(), size); - auto description = fds().file_description(fd); - if (!description) - return EBADF; + auto description = TRY(fds().file_description(fd)); if (!description->is_readable()) return EBADF; if (description->is_directory()) |