2019-04-17 17:15:55 +00:00
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2023-04-07 16:41:23 +00:00
|
|
|
//go:build aix || solaris
|
2019-04-17 17:15:55 +00:00
|
|
|
|
|
|
|
package unix
|
|
|
|
|
2019-10-02 20:56:28 +00:00
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ioctl itself should not be exposed directly, but additional get/set
|
|
|
|
// functions for specific types are permissible.
|
|
|
|
|
|
|
|
// IoctlSetInt performs an ioctl operation which sets an integer value
|
|
|
|
// on fd, using the specified request number.
|
2023-04-07 16:41:23 +00:00
|
|
|
func IoctlSetInt(fd int, req int, value int) error {
|
2019-10-02 20:56:28 +00:00
|
|
|
return ioctl(fd, req, uintptr(value))
|
|
|
|
}
|
2019-04-17 17:15:55 +00:00
|
|
|
|
2020-09-09 18:09:42 +00:00
|
|
|
// IoctlSetPointerInt performs an ioctl operation which sets an
|
|
|
|
// integer value on fd, using the specified request number. The ioctl
|
|
|
|
// argument is called with a pointer to the integer value, rather than
|
|
|
|
// passing the integer value directly.
|
2023-04-07 16:41:23 +00:00
|
|
|
func IoctlSetPointerInt(fd int, req int, value int) error {
|
2020-09-09 18:09:42 +00:00
|
|
|
v := int32(value)
|
2023-04-07 16:41:23 +00:00
|
|
|
return ioctlPtr(fd, req, unsafe.Pointer(&v))
|
2020-09-09 18:09:42 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 17:15:55 +00:00
|
|
|
// IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
|
|
|
|
//
|
|
|
|
// To change fd's window size, the req argument should be TIOCSWINSZ.
|
2023-04-07 16:41:23 +00:00
|
|
|
func IoctlSetWinsize(fd int, req int, value *Winsize) error {
|
2019-04-17 17:15:55 +00:00
|
|
|
// TODO: if we get the chance, remove the req parameter and
|
|
|
|
// hardcode TIOCSWINSZ.
|
2023-04-07 16:41:23 +00:00
|
|
|
return ioctlPtr(fd, req, unsafe.Pointer(value))
|
2019-04-17 17:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IoctlSetTermios performs an ioctl on fd with a *Termios.
|
|
|
|
//
|
|
|
|
// The req value will usually be TCSETA or TIOCSETA.
|
2023-04-07 16:41:23 +00:00
|
|
|
func IoctlSetTermios(fd int, req int, value *Termios) error {
|
2019-04-17 17:15:55 +00:00
|
|
|
// TODO: if we get the chance, remove the req parameter.
|
2023-04-07 16:41:23 +00:00
|
|
|
return ioctlPtr(fd, req, unsafe.Pointer(value))
|
2019-04-17 17:15:55 +00:00
|
|
|
}
|
2019-10-02 20:56:28 +00:00
|
|
|
|
|
|
|
// IoctlGetInt performs an ioctl operation which gets an integer value
|
|
|
|
// from fd, using the specified request number.
|
|
|
|
//
|
|
|
|
// A few ioctl requests use the return value as an output parameter;
|
|
|
|
// for those, IoctlRetInt should be used instead of this function.
|
2023-04-07 16:41:23 +00:00
|
|
|
func IoctlGetInt(fd int, req int) (int, error) {
|
2019-10-02 20:56:28 +00:00
|
|
|
var value int
|
2023-04-07 16:41:23 +00:00
|
|
|
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
|
2019-10-02 20:56:28 +00:00
|
|
|
return value, err
|
|
|
|
}
|
|
|
|
|
2023-04-07 16:41:23 +00:00
|
|
|
func IoctlGetWinsize(fd int, req int) (*Winsize, error) {
|
2019-10-02 20:56:28 +00:00
|
|
|
var value Winsize
|
2023-04-07 16:41:23 +00:00
|
|
|
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
|
2019-10-02 20:56:28 +00:00
|
|
|
return &value, err
|
|
|
|
}
|
|
|
|
|
2023-04-07 16:41:23 +00:00
|
|
|
func IoctlGetTermios(fd int, req int) (*Termios, error) {
|
2019-10-02 20:56:28 +00:00
|
|
|
var value Termios
|
2023-04-07 16:41:23 +00:00
|
|
|
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
|
2019-10-02 20:56:28 +00:00
|
|
|
return &value, err
|
|
|
|
}
|