vendor/golang.org/x/sys/unix/ioctl.go
author Mikael Berthe <mikael@lilotux.net>
Sat, 04 Feb 2023 12:58:35 +0100
changeset 265 05c40b36d3b2
parent 256 6d9efbef00a9
permissions -rw-r--r--
Bump to version 3.0.0-dev, using madon v3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
242
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     1
// Copyright 2018 The Go Authors. All rights reserved.
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     2
// Use of this source code is governed by a BSD-style
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     3
// license that can be found in the LICENSE file.
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     4
265
05c40b36d3b2 Bump to version 3.0.0-dev, using madon v3
Mikael Berthe <mikael@lilotux.net>
parents: 256
diff changeset
     5
//go:build aix || darwin || dragonfly || freebsd || hurd || linux || netbsd || openbsd || solaris
05c40b36d3b2 Bump to version 3.0.0-dev, using madon v3
Mikael Berthe <mikael@lilotux.net>
parents: 256
diff changeset
     6
// +build aix darwin dragonfly freebsd hurd linux netbsd openbsd solaris
242
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     7
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     8
package unix
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     9
251
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    10
import (
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    11
	"runtime"
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    12
	"unsafe"
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    13
)
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    14
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    15
// ioctl itself should not be exposed directly, but additional get/set
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    16
// functions for specific types are permissible.
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    17
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    18
// IoctlSetInt performs an ioctl operation which sets an integer value
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    19
// on fd, using the specified request number.
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    20
func IoctlSetInt(fd int, req uint, value int) error {
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    21
	return ioctl(fd, req, uintptr(value))
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    22
}
242
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    23
256
6d9efbef00a9 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 251
diff changeset
    24
// IoctlSetPointerInt performs an ioctl operation which sets an
6d9efbef00a9 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 251
diff changeset
    25
// integer value on fd, using the specified request number. The ioctl
6d9efbef00a9 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 251
diff changeset
    26
// argument is called with a pointer to the integer value, rather than
6d9efbef00a9 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 251
diff changeset
    27
// passing the integer value directly.
6d9efbef00a9 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 251
diff changeset
    28
func IoctlSetPointerInt(fd int, req uint, value int) error {
6d9efbef00a9 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 251
diff changeset
    29
	v := int32(value)
6d9efbef00a9 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 251
diff changeset
    30
	return ioctl(fd, req, uintptr(unsafe.Pointer(&v)))
6d9efbef00a9 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 251
diff changeset
    31
}
6d9efbef00a9 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 251
diff changeset
    32
242
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    33
// IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    34
//
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    35
// To change fd's window size, the req argument should be TIOCSWINSZ.
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    36
func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    37
	// TODO: if we get the chance, remove the req parameter and
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    38
	// hardcode TIOCSWINSZ.
251
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    39
	err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
242
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    40
	runtime.KeepAlive(value)
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    41
	return err
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    42
}
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    43
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    44
// IoctlSetTermios performs an ioctl on fd with a *Termios.
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    45
//
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    46
// The req value will usually be TCSETA or TIOCSETA.
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    47
func IoctlSetTermios(fd int, req uint, value *Termios) error {
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    48
	// TODO: if we get the chance, remove the req parameter.
251
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    49
	err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
242
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    50
	runtime.KeepAlive(value)
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    51
	return err
2a9ec03fe5a1 Use vendoring for backward compatibility
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    52
}
251
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    53
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    54
// IoctlGetInt performs an ioctl operation which gets an integer value
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    55
// from fd, using the specified request number.
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    56
//
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    57
// A few ioctl requests use the return value as an output parameter;
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    58
// for those, IoctlRetInt should be used instead of this function.
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    59
func IoctlGetInt(fd int, req uint) (int, error) {
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    60
	var value int
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    61
	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    62
	return value, err
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    63
}
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    64
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    65
func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    66
	var value Winsize
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    67
	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    68
	return &value, err
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    69
}
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    70
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    71
func IoctlGetTermios(fd int, req uint) (*Termios, error) {
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    72
	var value Termios
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    73
	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    74
	return &value, err
1c52a0eeb952 Update dependencies
Mikael Berthe <mikael@lilotux.net>
parents: 242
diff changeset
    75
}