diff --git a/kernel/src/sys/stdio.cpp b/kernel/src/sys/stdio.cpp index fa20d141..255a92d8 100644 --- a/kernel/src/sys/stdio.cpp +++ b/kernel/src/sys/stdio.cpp @@ -48,29 +48,17 @@ void sys_read(Context* context, int fd, size_t size, char* buffer) if (!buffer) { STDIO_FAIL(read, EINVAL); - context->rax = -EINVAL; + context->rax = -EINVAL; // FIXME: This should probably return EFAULT. return; } - if (fd >= TASK_MAX_FDS) - { - STDIO_FAIL(read, EBADF); - context->rax = -EBADF; - return; - } - if (fd < 0) + if (fd >= TASK_MAX_FDS || fd < 0) { STDIO_FAIL(read, EBADF); context->rax = -EBADF; return; } Task* current_task = Scheduler::current_task(); - if (!current_task->files[fd].is_open()) - { - STDIO_FAIL(read, EBADF); - context->rax = -EBADF; - return; - } - if (!current_task->files[fd].can_read()) + if (!current_task->files[fd].is_open() || !current_task->files[fd].can_read()) { STDIO_FAIL(read, EBADF); context->rax = -EBADF; @@ -83,13 +71,7 @@ void sys_read(Context* context, int fd, size_t size, char* buffer) void sys_close(Context* context, int fd) { - if (fd >= TASK_MAX_FDS) - { - STDIO_FAIL(close, EBADF); - context->rax = -EBADF; - return; - } - if (fd < 0) + if (fd >= TASK_MAX_FDS || fd < 0) { STDIO_FAIL(close, EBADF); context->rax = -EBADF;