Source file src/syscall/syscall_illumos.go

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

View as plain text