Refactor sys/stdio.cpp
This commit is contained in:
parent
2a755fcd93
commit
81815a0bdd
@ -48,29 +48,17 @@ void sys_read(Context* context, int fd, size_t size, char* buffer)
|
|||||||
if (!buffer)
|
if (!buffer)
|
||||||
{
|
{
|
||||||
STDIO_FAIL(read, EINVAL);
|
STDIO_FAIL(read, EINVAL);
|
||||||
context->rax = -EINVAL;
|
context->rax = -EINVAL; // FIXME: This should probably return EFAULT.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fd >= TASK_MAX_FDS)
|
if (fd >= TASK_MAX_FDS || fd < 0)
|
||||||
{
|
|
||||||
STDIO_FAIL(read, EBADF);
|
|
||||||
context->rax = -EBADF;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (fd < 0)
|
|
||||||
{
|
{
|
||||||
STDIO_FAIL(read, EBADF);
|
STDIO_FAIL(read, EBADF);
|
||||||
context->rax = -EBADF;
|
context->rax = -EBADF;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Task* current_task = Scheduler::current_task();
|
Task* current_task = Scheduler::current_task();
|
||||||
if (!current_task->files[fd].is_open())
|
if (!current_task->files[fd].is_open() || !current_task->files[fd].can_read())
|
||||||
{
|
|
||||||
STDIO_FAIL(read, EBADF);
|
|
||||||
context->rax = -EBADF;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!current_task->files[fd].can_read())
|
|
||||||
{
|
{
|
||||||
STDIO_FAIL(read, EBADF);
|
STDIO_FAIL(read, EBADF);
|
||||||
context->rax = -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)
|
void sys_close(Context* context, int fd)
|
||||||
{
|
{
|
||||||
if (fd >= TASK_MAX_FDS)
|
if (fd >= TASK_MAX_FDS || fd < 0)
|
||||||
{
|
|
||||||
STDIO_FAIL(close, EBADF);
|
|
||||||
context->rax = -EBADF;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (fd < 0)
|
|
||||||
{
|
{
|
||||||
STDIO_FAIL(close, EBADF);
|
STDIO_FAIL(close, EBADF);
|
||||||
context->rax = -EBADF;
|
context->rax = -EBADF;
|
||||||
|
Loading…
Reference in New Issue
Block a user