2021-11-07 20:44:48 +01:00
|
|
|
// Copyright 2020 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.
|
|
|
|
|
|
|
|
//go:build zos && s390x
|
|
|
|
|
|
|
|
package unix
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
"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-10 18:08:34 +02:00
|
|
|
func IoctlSetInt(fd int, req int, value int) error {
|
2021-11-07 20:44:48 +01:00
|
|
|
return ioctl(fd, req, uintptr(value))
|
|
|
|
}
|
|
|
|
|
|
|
|
// IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
|
|
|
|
//
|
|
|
|
// To change fd's window size, the req argument should be TIOCSWINSZ.
|
2023-04-10 18:08:34 +02:00
|
|
|
func IoctlSetWinsize(fd int, req int, value *Winsize) error {
|
2021-11-07 20:44:48 +01:00
|
|
|
// TODO: if we get the chance, remove the req parameter and
|
|
|
|
// hardcode TIOCSWINSZ.
|
2023-03-05 22:30:42 +01:00
|
|
|
return ioctlPtr(fd, req, unsafe.Pointer(value))
|
2021-11-07 20:44:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// IoctlSetTermios performs an ioctl on fd with a *Termios.
|
|
|
|
//
|
|
|
|
// The req value is expected to be TCSETS, TCSETSW, or TCSETSF
|
2023-04-10 18:08:34 +02:00
|
|
|
func IoctlSetTermios(fd int, req int, value *Termios) error {
|
2021-11-07 20:44:48 +01:00
|
|
|
if (req != TCSETS) && (req != TCSETSW) && (req != TCSETSF) {
|
|
|
|
return ENOSYS
|
|
|
|
}
|
|
|
|
err := Tcsetattr(fd, int(req), value)
|
|
|
|
runtime.KeepAlive(value)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-10 18:08:34 +02:00
|
|
|
func IoctlGetInt(fd int, req int) (int, error) {
|
2021-11-07 20:44:48 +01:00
|
|
|
var value int
|
2023-03-05 22:30:42 +01:00
|
|
|
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
|
2021-11-07 20:44:48 +01:00
|
|
|
return value, err
|
|
|
|
}
|
|
|
|
|
2023-04-10 18:08:34 +02:00
|
|
|
func IoctlGetWinsize(fd int, req int) (*Winsize, error) {
|
2021-11-07 20:44:48 +01:00
|
|
|
var value Winsize
|
2023-03-05 22:30:42 +01:00
|
|
|
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
|
2021-11-07 20:44:48 +01:00
|
|
|
return &value, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// IoctlGetTermios performs an ioctl on fd with a *Termios.
|
|
|
|
//
|
|
|
|
// The req value is expected to be TCGETS
|
2023-04-10 18:08:34 +02:00
|
|
|
func IoctlGetTermios(fd int, req int) (*Termios, error) {
|
2021-11-07 20:44:48 +01:00
|
|
|
var value Termios
|
|
|
|
if req != TCGETS {
|
|
|
|
return &value, ENOSYS
|
|
|
|
}
|
|
|
|
err := Tcgetattr(fd, &value)
|
|
|
|
return &value, err
|
|
|
|
}
|