hare

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

commit 609593785c8dfbdf4b3ecddd674b99635558ab83
parent 3b4410e5e63327b941e2fc0e3a4339ca75009b16
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 31 Jan 2021 12:47:14 -0500

rt: add errno wrapping helpers

We may want to update the syscall wrappers to return tagged unions
instead of raw syscall exits at some point.

Diffstat:
Mrt/+linux/errno.ha | 15+++++++++++++++
Mrt/+linux/syscalls.ha | 5+++++
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/rt/+linux/errno.ha b/rt/+linux/errno.ha @@ -1,3 +1,18 @@ +// Represents an error returned from the Linux kernel. +export type errno = int; + +// Given an integer error number, wraps it in an error type. +export fn wrap_errno(err: int) errno = err: errno; + +// Checks the return value from a Linux syscall and, if found to be in error, +// returns the appropriate error. Otherwise, returns the original value. +export fn wrap_return(r: size) (errno | size) = { + if (r > -4096z) { + return (-(r: i64)): int: errno; + }; + return r; +}; + export def EPERM: int = 1; export def ENOENT: int = 2; export def ESRCH: int = 3; diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -6,6 +6,11 @@ fn syscall4(u64, u64, u64, u64, u64) u64; fn syscall5(u64, u64, u64, u64, u64, u64) u64; fn syscall6(u64, u64, u64, u64, u64, u64, u64) u64; +export fn close(fd: int) int = syscall1(SYS_close, fd: u64): int; + +export fn read(fd: int, buf: *void, count: size) size = + syscall3(SYS_read, fd: u64, buf: uintptr: u64, count: u64): size; + export fn write(fd: int, buf: *const void, count: size) size = syscall3(SYS_write, fd: u64, buf: uintptr: u64, count: u64): size;