Created
February 6, 2021 05:41
-
-
Save djberg96/d45f1155bbf713c3d2c40d1675a30b3c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sys::Info | |
VERSION = "0.1.0" | |
lib LibC | |
struct Uname | |
sysname : ::LibC::Char[256] | |
nodename : ::LibC::Char[256] | |
release : ::LibC::Char[256] | |
version : ::LibC::Char[256] | |
machine : ::LibC::Char[256] | |
end | |
fun uname(value : Uname*) : Int32 | |
end | |
struct Uname | |
getter cstruct | |
def initialize(@cstruct : LibC::Uname) | |
end | |
macro get(prop) | |
def {{prop}} | |
String.new(cstruct.{{prop}}.to_unsafe) | |
end | |
end | |
get sysname | |
get nodename | |
get release | |
get version | |
get machine | |
end | |
def self.uname | |
uname_struct = LibC::Uname.new | |
if LibC.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