From cd2c276457edda6df7fb04895d3fd6a6add42926 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 17 Jul 2017 12:05:24 +0200 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- unix/linux/types.go | 3 +++ unix/syscall_linux.go | 14 ++++++++++++-- unix/ztypes_linux_386.go | 7 +++++++ unix/ztypes_linux_amd64.go | 7 +++++++ unix/ztypes_linux_arm.go | 7 +++++++ unix/ztypes_linux_arm64.go | 7 +++++++ unix/ztypes_linux_mips.go | 7 +++++++ unix/ztypes_linux_mips64.go | 7 +++++++ unix/ztypes_linux_mips64le.go | 7 +++++++ unix/ztypes_linux_mipsle.go | 7 +++++++ unix/ztypes_linux_ppc64.go | 7 +++++++ unix/ztypes_linux_ppc64le.go | 7 +++++++ unix/ztypes_linux_s390x.go | 7 +++++++ 13 files changed, 92 insertions(+), 2 deletions(-) diff --git a/unix/linux/types.go b/unix/linux/types.go index 9b69e271..56eb4c12 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -28,6 +28,7 @@ package unix #include #include #include +#include #include #include #include @@ -543,3 +544,5 @@ const _SC_PAGESIZE = C._SC_PAGESIZE // Terminal handling type Termios C.termios_t + +type Winsize C.struct_winsize diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index a6ac8e92..056f6010 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -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))) diff --git a/unix/ztypes_linux_386.go b/unix/ztypes_linux_386.go index 81112065..fe539a06 100644 --- a/unix/ztypes_linux_386.go +++ b/unix/ztypes_linux_386.go @@ -676,3 +676,10 @@ type Termios struct { Ispeed uint32 Ospeed uint32 } + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} diff --git a/unix/ztypes_linux_amd64.go b/unix/ztypes_linux_amd64.go index 075d9c56..e99cd797 100644 --- a/unix/ztypes_linux_amd64.go +++ b/unix/ztypes_linux_amd64.go @@ -694,3 +694,10 @@ type Termios struct { Ispeed uint32 Ospeed uint32 } + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} diff --git a/unix/ztypes_linux_arm.go b/unix/ztypes_linux_arm.go index a66c1603..0857aa6e 100644 --- a/unix/ztypes_linux_arm.go +++ b/unix/ztypes_linux_arm.go @@ -665,3 +665,10 @@ type Termios struct { Ispeed uint32 Ospeed uint32 } + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} diff --git a/unix/ztypes_linux_arm64.go b/unix/ztypes_linux_arm64.go index b3b506a6..fb1c90a9 100644 --- a/unix/ztypes_linux_arm64.go +++ b/unix/ztypes_linux_arm64.go @@ -673,3 +673,10 @@ type Termios struct { Ispeed uint32 Ospeed uint32 } + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} diff --git a/unix/ztypes_linux_mips.go b/unix/ztypes_linux_mips.go index 5c654f55..d15c9f4a 100644 --- a/unix/ztypes_linux_mips.go +++ b/unix/ztypes_linux_mips.go @@ -670,3 +670,10 @@ type Termios struct { Ispeed uint32 Ospeed uint32 } + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} diff --git a/unix/ztypes_linux_mips64.go b/unix/ztypes_linux_mips64.go index 3f11fb65..a39d3624 100644 --- a/unix/ztypes_linux_mips64.go +++ b/unix/ztypes_linux_mips64.go @@ -675,3 +675,10 @@ type Termios struct { Ispeed uint32 Ospeed uint32 } + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} diff --git a/unix/ztypes_linux_mips64le.go b/unix/ztypes_linux_mips64le.go index 1a4ad57e..a05f082e 100644 --- a/unix/ztypes_linux_mips64le.go +++ b/unix/ztypes_linux_mips64le.go @@ -675,3 +675,10 @@ type Termios struct { Ispeed uint32 Ospeed uint32 } + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} diff --git a/unix/ztypes_linux_mipsle.go b/unix/ztypes_linux_mipsle.go index b3f0f30f..2ecdddcd 100644 --- a/unix/ztypes_linux_mipsle.go +++ b/unix/ztypes_linux_mipsle.go @@ -670,3 +670,10 @@ type Termios struct { Ispeed uint32 Ospeed uint32 } + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} diff --git a/unix/ztypes_linux_ppc64.go b/unix/ztypes_linux_ppc64.go index aeee27e0..33b8e55c 100644 --- a/unix/ztypes_linux_ppc64.go +++ b/unix/ztypes_linux_ppc64.go @@ -683,3 +683,10 @@ type Termios struct { Ispeed uint32 Ospeed uint32 } + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} diff --git a/unix/ztypes_linux_ppc64le.go b/unix/ztypes_linux_ppc64le.go index b8cb2c3b..987d4814 100644 --- a/unix/ztypes_linux_ppc64le.go +++ b/unix/ztypes_linux_ppc64le.go @@ -683,3 +683,10 @@ type Termios struct { Ispeed uint32 Ospeed uint32 } + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} diff --git a/unix/ztypes_linux_s390x.go b/unix/ztypes_linux_s390x.go index 58883f92..cf539ca9 100644 --- a/unix/ztypes_linux_s390x.go +++ b/unix/ztypes_linux_s390x.go @@ -700,3 +700,10 @@ type Termios struct { Ispeed uint32 Ospeed uint32 } + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +}