github.com/iDigitalFlame/xmt@v0.5.4/device/unix/zsyscall_dragonfly.go (about)

     1  //go:build dragonfly
     2  // +build dragonfly
     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  
    25  	_ "unsafe"
    26  )
    27  
    28  const errMemory = syscall.Errno(0xC)
    29  
    30  type utsName struct {
    31  	Sysname  [32]byte
    32  	Nodename [32]byte
    33  	Release  [32]byte
    34  	Version  [32]byte
    35  	Machine  [32]byte
    36  }
    37  
    38  func uname(u *utsName) error {
    39  	var (
    40  		m = []int32{0x1, 0x1}
    41  		c = uintptr(32)
    42  	)
    43  	if err := sysctl(m, &u.Sysname[0], &c, nil, 0); err != nil && err != errMemory {
    44  		return err
    45  	}
    46  	m[1], c = 0xA, 32
    47  	if err := sysctl(m, &u.Nodename[0], &c, nil, 0); err != nil && err != errMemory {
    48  		return err
    49  	}
    50  	m[1], c = 0x2, 32
    51  	if err := sysctl(m, &u.Release[0], &c, nil, 0); err != nil && err != errMemory {
    52  		return err
    53  	}
    54  	m[1], c = 0x4, 32
    55  	if err := sysctl(m, &u.Version[0], &c, nil, 0); err != nil && err != errMemory {
    56  		return err
    57  	}
    58  	m[0], m[1], c = 0x6, 0x1, 32
    59  	if err := sysctl(m, &u.Machine[0], &c, nil, 0); err != nil && err != errMemory {
    60  		return err
    61  	}
    62  	u.Sysname[31], u.Nodename[31] = 0, 0
    63  	u.Release[31], u.Machine[31] = 0, 0
    64  	for i := range u.Version {
    65  		if u.Version[i] == 0 {
    66  			break
    67  		}
    68  		if u.Version[i] == '\n' || u.Version[i] == '\t' {
    69  			if i == 31 {
    70  				u.Version[i] = 0
    71  				break
    72  			}
    73  			u.Version[i] = ' '
    74  		}
    75  	}
    76  	return nil
    77  }
    78  
    79  //go:linkname sysctl syscall.sysctl
    80  func sysctl(mib []int32, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error