Blame vendor/golang.org/x/sys/unix/ioctl.go

Packit 63bb0d
// Copyright 2018 The Go Authors. All rights reserved.
Packit 63bb0d
// Use of this source code is governed by a BSD-style
Packit 63bb0d
// license that can be found in the LICENSE file.
Packit 63bb0d
Packit 63bb0d
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
Packit 63bb0d
Packit 63bb0d
package unix
Packit 63bb0d
Packit 63bb0d
import (
Packit 63bb0d
	"runtime"
Packit 63bb0d
	"unsafe"
Packit 63bb0d
)
Packit 63bb0d
Packit 63bb0d
// ioctl itself should not be exposed directly, but additional get/set
Packit 63bb0d
// functions for specific types are permissible.
Packit 63bb0d
Packit 63bb0d
// IoctlSetInt performs an ioctl operation which sets an integer value
Packit 63bb0d
// on fd, using the specified request number.
Packit 63bb0d
func IoctlSetInt(fd int, req uint, value int) error {
Packit 63bb0d
	return ioctl(fd, req, uintptr(value))
Packit 63bb0d
}
Packit 63bb0d
Packit Service 3a6627
// IoctlSetPointerInt performs an ioctl operation which sets an
Packit Service 3a6627
// integer value on fd, using the specified request number. The ioctl
Packit Service 3a6627
// argument is called with a pointer to the integer value, rather than
Packit Service 3a6627
// passing the integer value directly.
Packit Service 3a6627
func IoctlSetPointerInt(fd int, req uint, value int) error {
Packit Service 3a6627
	v := int32(value)
Packit Service 3a6627
	return ioctl(fd, req, uintptr(unsafe.Pointer(&v)))
Packit Service 3a6627
}
Packit Service 3a6627
Packit 63bb0d
// IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
Packit 63bb0d
//
Packit 63bb0d
// To change fd's window size, the req argument should be TIOCSWINSZ.
Packit 63bb0d
func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
Packit 63bb0d
	// TODO: if we get the chance, remove the req parameter and
Packit 63bb0d
	// hardcode TIOCSWINSZ.
Packit 63bb0d
	err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
Packit 63bb0d
	runtime.KeepAlive(value)
Packit 63bb0d
	return err
Packit 63bb0d
}
Packit 63bb0d
Packit 63bb0d
// IoctlSetTermios performs an ioctl on fd with a *Termios.
Packit 63bb0d
//
Packit 63bb0d
// The req value will usually be TCSETA or TIOCSETA.
Packit 63bb0d
func IoctlSetTermios(fd int, req uint, value *Termios) error {
Packit 63bb0d
	// TODO: if we get the chance, remove the req parameter.
Packit 63bb0d
	err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
Packit 63bb0d
	runtime.KeepAlive(value)
Packit 63bb0d
	return err
Packit 63bb0d
}
Packit 63bb0d
Packit 63bb0d
// IoctlGetInt performs an ioctl operation which gets an integer value
Packit 63bb0d
// from fd, using the specified request number.
Packit 63bb0d
//
Packit 63bb0d
// A few ioctl requests use the return value as an output parameter;
Packit 63bb0d
// for those, IoctlRetInt should be used instead of this function.
Packit 63bb0d
func IoctlGetInt(fd int, req uint) (int, error) {
Packit 63bb0d
	var value int
Packit 63bb0d
	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
Packit 63bb0d
	return value, err
Packit 63bb0d
}
Packit 63bb0d
Packit 63bb0d
func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
Packit 63bb0d
	var value Winsize
Packit 63bb0d
	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
Packit 63bb0d
	return &value, err
Packit 63bb0d
}
Packit 63bb0d
Packit 63bb0d
func IoctlGetTermios(fd int, req uint) (*Termios, error) {
Packit 63bb0d
	var value Termios
Packit 63bb0d
	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
Packit 63bb0d
	return &value, err
Packit 63bb0d
}