Black Lives Matter. Support the Equal Justice Initiative.

Source file src/syscall/syscall_illumos.go

Documentation: syscall

     1  // Copyright 2020 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  //go:build illumos
     6  // +build illumos
     7  
     8  // Illumos system calls not present on Solaris.
     9  
    10  package syscall
    11  
    12  import "unsafe"
    13  
    14  //go:cgo_import_dynamic libc_accept4 accept4 "libsocket.so"
    15  //go:cgo_import_dynamic libc_flock flock "libc.so"
    16  
    17  //go:linkname procAccept4 libc_accept4
    18  //go:linkname procFlock libc_flock
    19  
    20  var (
    21  	procAccept4,
    22  	procFlock libcFunc
    23  )
    24  
    25  func Accept4(fd int, flags int) (int, Sockaddr, error) {
    26  	var rsa RawSockaddrAny
    27  	var addrlen _Socklen = SizeofSockaddrAny
    28  	nfd, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procAccept4)), 4, uintptr(fd), uintptr(unsafe.Pointer(&rsa)), uintptr(unsafe.Pointer(&addrlen)), uintptr(flags), 0, 0)
    29  	if errno != 0 {
    30  		return 0, nil, errno
    31  	}
    32  	if addrlen > SizeofSockaddrAny {
    33  		panic("RawSockaddrAny too small")
    34  	}
    35  	sa, err := anyToSockaddr(&rsa)
    36  	if err != nil {
    37  		Close(int(nfd))
    38  		return 0, nil, err
    39  	}
    40  	return int(nfd), sa, nil
    41  }
    42  
    43  func Flock(fd int, how int) error {
    44  	_, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procFlock)), 2, uintptr(fd), uintptr(how), 0, 0, 0, 0)
    45  	if errno != 0 {
    46  		return errno
    47  	}
    48  	return nil
    49  }
    50  

View as plain text