hare

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

commit 1100ca73a4e146697889b4a35c842314a0e411ca
parent 93ed90e8f5b258583da211f722762dd030de2ff9
Author: Cephon Altera <touko@cock.email>
Date:   Sat, 17 Feb 2024 16:52:26 +0300

added `os::hostname()` to OpenBSD

Added rt::MAXHOSTNAMELEN from /usr/include/sys/param.h as requested.

Signed-off-by: Cephon Altera <touko@cock.email>

Diffstat:
Mos/+openbsd/platform_environ.ha | 11+++++++++++
Mrt/+openbsd/types.ha | 2+-
2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/os/+openbsd/platform_environ.ha b/os/+openbsd/platform_environ.ha @@ -58,6 +58,17 @@ export fn sysname() const str = { return strings::fromutf8(buf[..(buf_sz -1)])!; }; +// Returns the host system hostname +export fn hostname() const str = { + let name: [2]int = [rt::CTL_KERN, rt::KERN_HOSTNAME]; + + static let buf: [rt::MAXHOSTNAMELEN]u8 = [0...]; + let buf_sz = len(buf); + + rt::sysctl(name, len(name): uint, &buf, &buf_sz, null, 0)!; + return strings::fromutf8(buf[..(buf_sz -1)])!; +}; + // Returns the host operating system version export fn version() const str = { let name: [2]int = [rt::CTL_KERN, rt::KERN_OSRELEASE]; diff --git a/rt/+openbsd/types.ha b/rt/+openbsd/types.ha @@ -222,7 +222,7 @@ export type dirent = struct { }; export def MAXNAMLEN: size = 255; - +export def MAXHOSTNAMELEN: size = 255; export def DT_UNKNOWN: u8 = 0; export def DT_FIFO: u8 = 1; export def DT_CHR: u8 = 2;