Commit cd2c2764 authored by Tobias Klauser's avatar Tobias Klauser Committed by Brad Fitzpatrick

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: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 4cd6d1a8
......@@ -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
......@@ -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)))
......
......@@ -676,3 +676,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}
......@@ -694,3 +694,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}
......@@ -665,3 +665,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}
......@@ -673,3 +673,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}
......@@ -670,3 +670,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}
......@@ -675,3 +675,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}
......@@ -675,3 +675,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}
......@@ -670,3 +670,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}
......@@ -683,3 +683,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}
......@@ -683,3 +683,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}
......@@ -700,3 +700,10 @@ type Termios struct {
Ispeed uint32
Ospeed uint32
}
type Winsize struct {
Row uint16
Col uint16
Xpixel uint16
Ypixel uint16
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment