github.com/neonyo/sys@v0.0.0-20230720094341-b1ee14be3ce8/unix/syscall_illumos.go (about)

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // illumos system calls not present on Solaris.
     6  
     7  //go:build amd64 && illumos
     8  // +build amd64,illumos
     9  
    10  package unix
    11  
    12  import (
    13  	"unsafe"
    14  )
    15  
    16  func bytes2iovec(bs [][]byte) []Iovec {
    17  	iovecs := make([]Iovec, len(bs))
    18  	for i, b := range bs {
    19  		iovecs[i].SetLen(len(b))
    20  		if len(b) > 0 {
    21  			iovecs[i].Base = &b[0]
    22  		} else {
    23  			iovecs[i].Base = (*byte)(unsafe.Pointer(&_zero))
    24  		}
    25  	}
    26  	return iovecs
    27  }
    28  
    29  //sys	readv(fd int, iovs []Iovec) (n int, err error)
    30  
    31  func Readv(fd int, iovs [][]byte) (n int, err error) {
    32  	iovecs := bytes2iovec(iovs)
    33  	n, err = readv(fd, iovecs)
    34  	return n, err
    35  }
    36  
    37  //sys	preadv(fd int, iovs []Iovec, off int64) (n int, err error)
    38  
    39  func Preadv(fd int, iovs [][]byte, off int64) (n int, err error) {
    40  	iovecs := bytes2iovec(iovs)
    41  	n, err = preadv(fd, iovecs, off)
    42  	return n, err
    43  }
    44  
    45  //sys	writev(fd int, iovs []Iovec) (n int, err error)
    46  
    47  func Writev(fd int, iovs [][]byte) (n int, err error) {
    48  	iovecs := bytes2iovec(iovs)
    49  	n, err = writev(fd, iovecs)
    50  	return n, err
    51  }
    52  
    53  //sys	pwritev(fd int, iovs []Iovec, off int64) (n int, err error)
    54  
    55  func Pwritev(fd int, iovs [][]byte, off int64) (n int, err error) {
    56  	iovecs := bytes2iovec(iovs)
    57  	n, err = pwritev(fd, iovecs, off)
    58  	return n, err
    59  }
    60  
    61  //sys	accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) = libsocket.accept4
    62  
    63  func Accept4(fd int, flags int) (nfd int, sa Sockaddr, err error) {
    64  	var rsa RawSockaddrAny
    65  	var len _Socklen = SizeofSockaddrAny
    66  	nfd, err = accept4(fd, &rsa, &len, flags)
    67  	if err != nil {
    68  		return
    69  	}
    70  	if len > SizeofSockaddrAny {
    71  		panic("RawSockaddrAny too small")
    72  	}
    73  	sa, err = anyToSockaddr(fd, &rsa)
    74  	if err != nil {
    75  		Close(nfd)
    76  		nfd = 0
    77  	}
    78  	return
    79  }