github.com/iDigitalFlame/xmt@v0.5.4/device/unix/unix.go (about) 1 //go:build !js && !plan9 && !windows 2 // +build !js,!plan9,!windows 3 4 // Copyright (C) 2020 - 2023 iDigitalFlame 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see <https://www.gnu.org/licenses/>. 18 // 19 20 // Package unix is a nix* specific package that assists with calling Unix/Linux/BSD 21 // specific functions and data gathering. 22 package unix 23 24 // Release returns the system "uname" release version as a string. The underlying 25 // system call is depdent on the underlying system. 26 // 27 // If any errors occur, this functions returns an empty string. 28 func Release() string { 29 var ( 30 u utsName 31 err = uname(&u) 32 ) 33 if err != nil { 34 return "" 35 } 36 var ( 37 v [257]byte 38 i int 39 ) 40 for ; i < len(u.Release); i++ { 41 if u.Release[i] == 0 { 42 break 43 } 44 v[i] = byte(u.Release[i]) 45 } 46 return string(v[:i]) 47 } 48 49 // IsMachine64 returns true if the underlying kernel reports the machine type as 50 // one that runs on a 64bit CPU (in 64bit mode). Otherwise, it returns false. 51 // 52 // If any errors occur, this functions returns false. 53 func IsMachine64() bool { 54 var ( 55 u utsName 56 err = uname(&u) 57 ) 58 if err != nil { 59 return false 60 } 61 switch { 62 case u.Machine[10] == 0 && u.Machine[0] == 'a' && u.Machine[6] == '4' && u.Machine[5] == '6' && u.Machine[9] == 'e': // Match aarch64_be 63 case u.Machine[7] == 0 && u.Machine[0] == 'a' && u.Machine[6] == '4' && u.Machine[5] == '6': // Match aarch64 64 case u.Machine[6] == 0 && u.Machine[0] == 'a' && u.Machine[4] == '8' && u.Machine[3] == 'v': // Match armv8l and armv8b 65 case u.Machine[6] == 0 && u.Machine[0] == 'x' && u.Machine[5] == '4' && u.Machine[4] == '6': // Match x86_64 66 default: 67 return false 68 } 69 return true 70 }