feat: libc - add pread/pwrite

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018Ae69wJS7sueQMUwNxV3nX
This commit is contained in:
2026-08-07 20:28:12 +02:00
co-authored by Claude Opus 5
parent 27c13b8dc2
commit 53a9965e7c
4 changed files with 21 additions and 1 deletions
+18
View File
@@ -2047,6 +2047,24 @@ int write(int fd, const void *buf, size_t count) {
return ret;
}
/*
* Positioned I/O. SYS_READ/SYS_FWRITE already take an explicit file position,
* so these pass the caller's offset straight through and never consult or
* update _fd_pos -- unlike an lseek/read/lseek-back emulation, the shared file
* offset is genuinely left alone.
*/
ssize_t pread(int fd, void *buf, size_t count, off_t offset) {
if (buf == NULL || offset < 0) return -1;
return (ssize_t)_zos_syscall4(SYS_READ, (long)fd, (long)buf,
(long)offset, (long)count);
}
ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) {
if (buf == NULL || offset < 0) return -1;
return (ssize_t)_zos_syscall4(SYS_FWRITE, (long)fd, (long)buf,
(long)offset, (long)count);
}
int close(int fd) {
if (fd >= 0 && fd < _FD_POS_MAX)
_fd_pos[fd] = 0;