LibC: Write mostly functioning stdio
This commit is contained in:
@@ -304,6 +304,15 @@ namespace Kernel
|
||||
return ret;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> Process::seek(int fd, size_t offset)
|
||||
{
|
||||
LockGuard _(m_lock);
|
||||
TRY(validate_fd(fd));
|
||||
auto& open_fd = open_file_description(fd);
|
||||
open_fd.offset = offset;
|
||||
return {};
|
||||
}
|
||||
|
||||
BAN::ErrorOr<BAN::Vector<BAN::String>> Process::read_directory_entries(int fd)
|
||||
{
|
||||
OpenFileDescription open_fd_copy;
|
||||
@@ -349,6 +358,14 @@ namespace Kernel
|
||||
return {};
|
||||
}
|
||||
|
||||
void Process::termid(char* buffer) const
|
||||
{
|
||||
if (m_tty == nullptr)
|
||||
buffer[0] = '\0';
|
||||
strcpy(buffer, "/dev/");
|
||||
strcpy(buffer + 5, m_tty->name().data());
|
||||
}
|
||||
|
||||
BAN::ErrorOr<BAN::String> Process::absolute_path_of(BAN::StringView path) const
|
||||
{
|
||||
if (path.empty())
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Kernel
|
||||
{
|
||||
auto res = Process::current().read(fd, buffer, size);
|
||||
if (res.is_error())
|
||||
return res.error().get_error_code();
|
||||
return -res.error().get_error_code();
|
||||
return res.value();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,36 @@ namespace Kernel
|
||||
{
|
||||
auto res = Process::current().write(fd, buffer, size);
|
||||
if (res.is_error())
|
||||
return res.error().get_error_code();
|
||||
return -res.error().get_error_code();
|
||||
return res.value();
|
||||
}
|
||||
|
||||
int sys_close(int fd)
|
||||
{
|
||||
auto res = Process::current().close(fd);
|
||||
if (res.is_error())
|
||||
return -res.error().get_error_code();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sys_seek(int fd, long offset)
|
||||
{
|
||||
auto res = Process::current().seek(fd, offset);
|
||||
if (res.is_error())
|
||||
return -res.error().get_error_code();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sys_termid(char* buffer)
|
||||
{
|
||||
Process::current().termid(buffer);
|
||||
}
|
||||
|
||||
int sys_open(const char* path, int oflags)
|
||||
{
|
||||
auto res = Process::current().open(path, oflags);
|
||||
if (res.is_error())
|
||||
return -res.error().get_error_code();
|
||||
return res.value();
|
||||
}
|
||||
|
||||
@@ -44,10 +73,20 @@ namespace Kernel
|
||||
case SYS_WRITE:
|
||||
ret = sys_write((int)(uintptr_t)arg1, arg2, (size_t)(uintptr_t)arg3);
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
dprintln("Unknown syscall");
|
||||
case SYS_TERMID:
|
||||
sys_termid((char*)arg1);
|
||||
break;
|
||||
case SYS_CLOSE:
|
||||
ret = sys_close((int)(uintptr_t)arg1);
|
||||
break;
|
||||
case SYS_SEEK:
|
||||
ret = sys_seek((int)(uintptr_t)arg1, (long)arg2);
|
||||
break;
|
||||
case SYS_OPEN:
|
||||
ret = sys_open((const char*)arg1, (int)(uintptr_t)arg2);
|
||||
break;
|
||||
default:
|
||||
Kernel::panic("Unknown syscall {}", syscall);
|
||||
}
|
||||
|
||||
asm volatile("cli");
|
||||
|
||||
Reference in New Issue
Block a user