unix: add ioctl functions to get/set terminal window size on Linux

Add IoctlGetWinsize and IoctlSetWinsize to retreive and manipulate
Winsize structures on Linux, akin to the already existing implementation
on Solaris.

Also remove the named result parameter for IoctlSetInt and
IoctlSetTermios, as they add no additional use.

Change-Id: Id349d1d6a21d5c9a05943f4dcc3a275613ccf7b8
Reviewed-on: https://go-review.googlesource.com/49231
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Tobias Klauser
2017-07-17 12:05:24 +02:00
committed by Brad Fitzpatrick
parent 4cd6d1a821
commit cd2c276457
13 changed files with 92 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ package unix
#include <stdio.h>
#include <sys/epoll.h>
#include <sys/inotify.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mount.h>
#include <sys/param.h>
@@ -543,3 +544,5 @@ const _SC_PAGESIZE = C._SC_PAGESIZE
// Terminal handling
type Termios C.termios_t
type Winsize C.struct_winsize

View File

@@ -57,11 +57,15 @@ func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) {
// IoctlSetInt performs an ioctl operation which sets an integer value
// on fd, using the specified request number.
func IoctlSetInt(fd int, req uint, value int) (err error) {
func IoctlSetInt(fd int, req uint, value int) error {
return ioctl(fd, req, uintptr(value))
}
func IoctlSetTermios(fd int, req uint, value *Termios) (err error) {
func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
}
func IoctlSetTermios(fd int, req uint, value *Termios) error {
return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
}
@@ -73,6 +77,12 @@ func IoctlGetInt(fd int, req uint) (int, error) {
return value, err
}
func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
var value Winsize
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
return &value, err
}
func IoctlGetTermios(fd int, req uint) (*Termios, error) {
var value Termios
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))

View File

@@ -676,3 +676,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}

View File

@@ -694,3 +694,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}

View File

@@ -665,3 +665,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}

View File

@@ -673,3 +673,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}

View File

@@ -670,3 +670,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}

View File

@@ -675,3 +675,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}

View File

@@ -675,3 +675,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}

View File

@@ -670,3 +670,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}

View File

@@ -683,3 +683,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}

View File

@@ -683,3 +683,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}

View File

@@ -700,3 +700,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}