github.com/iDigitalFlame/xmt@v0.5.4/device/unix/zsyscall_bsd.go (about) 1 //go:build darwin || freebsd || netbsd || openbsd 2 // +build darwin freebsd netbsd openbsd 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 21 22 import ( 23 _ "syscall" 24 _ "unsafe" 25 ) 26 27 type utsName struct { 28 Sysname [256]byte 29 Nodename [256]byte 30 Release [256]byte 31 Version [256]byte 32 Machine [256]byte 33 } 34 35 func uname(u *utsName) error { 36 var ( 37 m = []int32{0x1, 0x1} 38 c = uintptr(256) 39 ) 40 if err := sysctl(m, &u.Sysname[0], &c, nil, 0); err != nil { 41 return err 42 } 43 m[1], c = 0xA, 256 44 if err := sysctl(m, &u.Nodename[0], &c, nil, 0); err != nil { 45 return err 46 } 47 m[1], c = 0x2, 256 48 if err := sysctl(m, &u.Release[0], &c, nil, 0); err != nil { 49 return err 50 } 51 m[1], c = 0x4, 256 52 if err := sysctl(m, &u.Version[0], &c, nil, 0); err != nil { 53 return err 54 } 55 m[0], m[1], c = 0x6, 0x1, 256 56 if err := sysctl(m, &u.Machine[0], &c, nil, 0); err != nil { 57 return err 58 } 59 for i := range u.Version { 60 if u.Version[i] == 0 { 61 break 62 } 63 if u.Version[i] == '\n' || u.Version[i] == '\t' { 64 if i == 255 { 65 u.Version[i] = 0 66 break 67 } 68 u.Version[i] = ' ' 69 } 70 } 71 return nil 72 } 73 74 //go:linkname sysctl syscall.sysctl 75 func sysctl(mib []int32, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error