hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit b4cabe39aba41f93be60d15a2503a105c4841ed4
parent 2321e5fad1032e670532f7aed9ec95009440a554
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue,  2 Feb 2021 22:35:28 -0500

os::fd_copy: refactor out the offset parameter

Diffstat:
Mos/+linux/fdstream.ha | 20++++----------------
Mrt/+linux/syscalls.ha | 2+-
2 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/os/+linux/fdstream.ha b/os/+linux/fdstream.ha @@ -5,7 +5,6 @@ use strings; type fd_stream = struct { stream: io::stream, fd: int, - offs: size, }; fn static_fdopen( @@ -19,7 +18,6 @@ fn static_fdopen( ... }, fd = fd, - offs = 0z, }; if (mode == io::mode::RDONLY || mode == io::mode::RDWR) { stream.stream.reader = &fd_read; @@ -64,10 +62,7 @@ fn fd_read(s: *io::stream, buf: []u8) (size | io::EOF | io::error) = { err: rt::errno => errno_to_io(err), n: size => switch (n) { 0z => io::EOF, - * => { - stream.offs += n; - n; - }, + * => n, }, }; }; @@ -77,10 +72,7 @@ fn fd_write(s: *io::stream, buf: const []u8) (size | io::error) = { let r = rt::write(stream.fd, buf: *const [*]u8, len(buf)); return match (rt::wrap_return(r)) { err: rt::errno => errno_to_io(err), - n: size => { - stream.offs += n; - n; - }, + n: size => n, }; }; @@ -105,10 +97,9 @@ fn fd_copy(_to: *io::stream, _from: *io::stream) (size | io::error) = { }; let to = _to: *fd_stream, from = _from: *fd_stream; - let offs = to.offs; let sum = 0z; for (true) { - let r = rt::sendfile(to.fd, from.fd, &offs, SENDFILE_MAX); + let r = rt::sendfile(to.fd, from.fd, null, SENDFILE_MAX); let n = match(rt::wrap_return(r)) { err: rt::errno => switch (err) { rt::EINVAL => { @@ -124,10 +115,7 @@ fn fd_copy(_to: *io::stream, _from: *io::stream) (size | io::error) = { * => n, }, }; - let w = offs - n; - sum += w; - to.offs += n; - from.offs += n; + sum += n; }; return sum; }; diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -19,7 +19,7 @@ export fn close(fd: int) int = syscall1(SYS_close, fd: u64): int; export fn getpid() int = syscall0(SYS_getpid): int; -export fn sendfile(out: int, in: int, offs: *size, count: size) size = +export fn sendfile(out: int, in: int, offs: nullable *size, count: size) size = syscall4(SYS_sendfile, out: u64, in: u64, offs: uintptr: u64, count: u64): size; export @noreturn fn exit(status: int) void = syscall1(SYS_exit, status: u64);