Created
September 28, 2017 18:23
-
-
Save aeppert/0c1a4598521267752226ef5e464d591b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "syscall" | |
| ) | |
| func UtsArrayToStr(in []int8) string { | |
| i, out := 0, make([]byte, 0, len(in)) | |
| for ; i < len(in); i++ { | |
| if in[i] == 0 { | |
| break | |
| } | |
| out = append(out, byte(in[i])) | |
| } | |
| return string(out) | |
| } | |
| func uname() (*syscall.Utsname, error) { | |
| uts := &syscall.Utsname{} | |
| if err := syscall.Uname(uts); err != nil { | |
| return nil, err | |
| } | |
| return uts, nil | |
| } | |
| func main() { | |
| u, e := uname() | |
| if e == nil { | |
| fmt.Println(UtsArrayToStr(u.Release[:])) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment