hare

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

commit 25c165ad428a6eb5d2942c782eda8b128a8f5cff
parent 4254f1ce78362b96d08bcbbba77e0647380b62e6
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sat,  6 Mar 2021 12:15:51 -0500

os: add uname functions

Diffstat:
Mos/+linux/environ.ha | 43+++++++++++++++++++++++++++++++++++++++++++
Mrt/+linux/syscalls.ha | 5+++++
Mrt/+linux/types.ha | 9+++++++++
3 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/os/+linux/environ.ha b/os/+linux/environ.ha @@ -60,3 +60,46 @@ export fn getenvs() []str = { }; return envp; }; + +let uts: rt::utsname = rt::utsname { ... }; +let uts_valid: bool = false; + +// Returns the host kernel name +export fn sysname() const str = { + if (!uts_valid) { + rt::uname(&uts) as void; + }; + return strings::from_c(&uts.sysname: *const char); +}; + +// Returns the host system hostname +export fn hostname() const str = { + if (!uts_valid) { + rt::uname(&uts) as void; + }; + return strings::from_c(&uts.nodename: *const char); +}; + +// Returns the host kernel version +export fn release() const str = { + if (!uts_valid) { + rt::uname(&uts) as void; + }; + return strings::from_c(&uts.release: *const char); +}; + +// Returns the host operating system version +export fn version() const str = { + if (!uts_valid) { + rt::uname(&uts) as void; + }; + return strings::from_c(&uts.version: *const char); +}; + +// Returns the host CPU architecture +export fn machine() const str = { + if (!uts_valid) { + rt::uname(&uts) as void; + }; + return strings::from_c(&uts.machine: *const char); +}; diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -248,3 +248,8 @@ export fn clock_gettime(clock_id: int, tp: *timespec) (void | errno) = { clock_id: u64, tp: uintptr: u64))?; return; }; + +export fn uname(uts: *utsname) (void | errno) = { + wrap_return(syscall1(SYS_uname, uts: uintptr: u64))?; + return; +}; diff --git a/rt/+linux/types.ha b/rt/+linux/types.ha @@ -295,3 +295,12 @@ export type rusage = struct { ru_nivcsw: u64, __reserved: [16]u64, }; + +export type utsname = struct { + sysname: [65]char, + nodename: [65]char, + release: [65]char, + version: [65]char, + machine: [65]char, + domainname: [65]char, +};