diff --git a/foreign_freebsd.odin b/foreign_freebsd.odin new file mode 100644 index 0000000..5373a41 --- /dev/null +++ b/foreign_freebsd.odin @@ -0,0 +1,8 @@ +package systeminfo + +import c "core:c/libc" + +@(default_calling_convention = "c") +foreign { + gethostname :: proc(hostname: ^[1024]u8, namelen: c.int) -> c.int --- +} diff --git a/foreign.odin b/foreign_linux.odin similarity index 78% rename from foreign.odin rename to foreign_linux.odin index 6ba48c6..e732064 100644 --- a/foreign.odin +++ b/foreign_linux.odin @@ -5,5 +5,4 @@ import c "core:c/libc" @(default_calling_convention = "c") foreign { statvfs :: proc(path: cstring, stat: ^Sys_statvfs) -> c.int --- - sysconf :: proc(name: int) -> c.long --- } diff --git a/systeminfo_freebsd.odin b/systeminfo_freebsd.odin new file mode 100644 index 0000000..4e69389 --- /dev/null +++ b/systeminfo_freebsd.odin @@ -0,0 +1,33 @@ +package systeminfo + +import "core:fmt" +import c "core:c/libc" +import "core:strings" +import "core:sys/unix" + +get_hostname :: proc() -> (hostname: string, ok: bool) #optional_ok { + ok = true + + hostname_array: [1024]u8 + err := gethostname(&hostname_array, i32(1023)) + if err != 0 { + ok = false + return + } + + hostname = strings.clone(string(hostname_array[:])) + + return +} + +get_system_uptime_in_seconds :: proc() -> (int, bool) { + tp: unix.timespec + + result := unix.clock_gettime(unix.CLOCK_MONOTONIC_RAW, &tp) + if result != 0 { + return 0, false + } + + return int(tp.tv_sec), true +} + diff --git a/systeminfo.odin b/systeminfo_linux.odin similarity index 100% rename from systeminfo.odin rename to systeminfo_linux.odin