source: code/trunk/vendor/golang.org/x/sys/unix/ioctl.go@ 822

Last change on this file since 822 was 822, checked in by yakumo.izuru, 22 months ago

Prefer immortal.run over runit and rc.d, use vendored modules
for convenience.

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

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