golang.org/x/sys@v0.20.1-0.20240517151509-673e0f94c16d/unix/ioctl_signed.go (about)

     1  // Copyright 2018 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 aix || solaris
     6  
     7  package unix
     8  
     9  import (
    10  	"unsafe"
    11  )
    12  
    13  // ioctl itself should not be exposed directly, but additional get/set
    14  // functions for specific types are permissible.
    15  
    16  // IoctlSetInt performs an ioctl operation which sets an integer value
    17  // on fd, using the specified request number.
    18  func IoctlSetInt(fd int, req int, value int) error {
    19  	return ioctl(fd, req, uintptr(value))
    20  }
    21  
    22  // IoctlSetPointerInt performs an ioctl operation which sets an
    23  // integer value on fd, using the specified request number. The ioctl
    24  // argument is called with a pointer to the integer value, rather than
    25  // passing the integer value directly.
    26  func IoctlSetPointerInt(fd int, req int, value int) error {
    27  	v := int32(value)
    28  	return ioctlPtr(fd, req, unsafe.Pointer(&v))
    29  }
    30  
    31  // IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
    32  //
    33  // To change fd's window size, the req argument should be TIOCSWINSZ.
    34  func IoctlSetWinsize(fd int, req int, value *Winsize) error {
    35  	// TODO: if we get the chance, remove the req parameter and
    36  	// hardcode TIOCSWINSZ.
    37  	return ioctlPtr(fd, req, unsafe.Pointer(value))
    38  }
    39  
    40  // IoctlSetTermios performs an ioctl on fd with a *Termios.
    41  //
    42  // The req value will usually be TCSETA or TIOCSETA.
    43  func IoctlSetTermios(fd int, req int, value *Termios) error {
    44  	// TODO: if we get the chance, remove the req parameter.
    45  	return ioctlPtr(fd, req, unsafe.Pointer(value))
    46  }
    47  
    48  // IoctlGetInt performs an ioctl operation which gets an integer value
    49  // from fd, using the specified request number.
    50  //
    51  // A few ioctl requests use the return value as an output parameter;
    52  // for those, IoctlRetInt should be used instead of this function.
    53  func IoctlGetInt(fd int, req int) (int, error) {
    54  	var value int
    55  	err := ioctlPtr(fd, req, unsafe.Pointer(&value))
    56  	return value, err
    57  }
    58  
    59  func IoctlGetWinsize(fd int, req int) (*Winsize, error) {
    60  	var value Winsize
    61  	err := ioctlPtr(fd, req, unsafe.Pointer(&value))
    62  	return &value, err
    63  }
    64  
    65  func IoctlGetTermios(fd int, req int) (*Termios, error) {
    66  	var value Termios
    67  	err := ioctlPtr(fd, req, unsafe.Pointer(&value))
    68  	return &value, err
    69  }