Skip to content

Commit

Permalink
kernel: sys: k_write should accept fd < 3 (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand authored Apr 1, 2022
1 parent d724050 commit bdccf41
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/kernel/sys/k_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

ssize_t k_write(int fd, const void* buf, size_t count)
{
#ifndef ENABLE_USERLAND_DEBUG
// This would conflict with the userland message being written.
SYS_DEBUG("fd=%d buf=%p count=%d", fd, buf, count);
#endif

if (fd == STDOUT || fd == STDERR) {
for (size_t i = 0; i < count; i++) {
arch_putchar(((const char*)buf)[i]);
Expand All @@ -19,16 +24,6 @@ ssize_t k_write(int fd, const void* buf, size_t count)
return count;
}

if (fd < 3) {
SYS_DEBUG("invalid file descriptor fd=%d", fd);
return -EPERM;
}

#ifndef ENABLE_USERLAND_DEBUG
// This would conflict with the userland message being written.
SYS_DEBUG("fd=%d buf=%p count=%d", fd, buf, count);
#endif

descriptor_t* desc = get_descriptor(fd);

if (desc == NULL) {
Expand Down

0 comments on commit bdccf41

Please sign in to comment.