LibCore: Add syscall wrappers for read() and write()

This commit is contained in:
Andreas Kling 2021-11-23 12:40:17 +01:00
parent 221a32577e
commit 16356ca478
Notes: sideshowbarker 2024-07-18 00:48:22 +09:00
2 changed files with 18 additions and 0 deletions

View file

@ -148,4 +148,20 @@ ErrorOr<struct stat> stat(StringView path)
#endif
}
ErrorOr<ssize_t> read(int fd, void* buffer, size_t buffer_size)
{
ssize_t rc = ::read(fd, buffer, buffer_size);
if (rc < 0)
return Error::from_syscall("read"sv, -errno);
return rc;
}
ErrorOr<ssize_t> write(int fd, void const* data, size_t data_size)
{
ssize_t rc = ::write(fd, data, data_size);
if (rc < 0)
return Error::from_syscall("write"sv, -errno);
return rc;
}
}

View file

@ -26,5 +26,7 @@ ErrorOr<int> open(StringView path, int options, ...);
ErrorOr<void> close(int fd);
ErrorOr<void> ftruncate(int fd, off_t length);
ErrorOr<struct stat> stat(StringView path);
ErrorOr<ssize_t> read(int fd, void* buffer, size_t buffer_size);
ErrorOr<ssize_t> write(int fd, void const* data, size_t data_size);
}