Skip to content

Instantly share code, notes, and snippets.

@djberg96
Created February 6, 2021 05:14
Show Gist options
  • Save djberg96/e9ee03c3d40b8a056d6788ca10fee743 to your computer and use it in GitHub Desktop.
Save djberg96/e9ee03c3d40b8a056d6788ca10fee743 to your computer and use it in GitHub Desktop.
module Sys::Info
VERSION = "0.1.0"
lib C
struct Uname
sysname : StaticArray(UInt8, 256)
nodename : StaticArray(UInt8, 256)
release : StaticArray(UInt8, 256)
version : StaticArray(UInt8, 256)
machine : StaticArray(UInt8, 256)
end
fun uname(value : Uname*) : Int32
end
struct Uname
getter cstruct
macro get(prop)
def {{prop}}
String.build do |io|
cstruct.{{prop}}.each do |n|
io.write_byte n.to_u8
end
end
end
end
def initialize(@cstruct : C::Uname)
end
get sysname
get nodename
get release
get version
get machine
end
def self.uname
uname_struct = C::Uname.new
if C.uname(pointerof(uname_struct)) < 0
raise "uname function call failed"
else
Uname.new(uname_struct)
end
end
end
uname = Sys::Info.uname
puts uname.sysname
puts uname.nodename
puts uname.release
puts uname.version
puts uname.machine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment