From b36040661688bbbde06c38ea80af105ebf21415b Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Fri, 30 Dec 2022 08:08:05 +0000 Subject: [PATCH] unix: support TIOCGETA on GNU/Hurd Add minimal support for GNU/Hurd to allow building third party packages which detect terminal support. Change-Id: Ia13fe8e9e4880e8ab062f9a2efb581320637f017 GitHub-Last-Rev: f612efbe7da35f618d1bd498a215f4b9da9c4f53 GitHub-Pull-Request: golang/sys#144 Reviewed-on: https://go-review.googlesource.com/c/sys/+/459895 Reviewed-by: Tobias Klauser Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov Reviewed-by: Ian Lance Taylor Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot --- unix/gccgo.go | 4 ++-- unix/gccgo_c.c | 4 ++-- unix/ioctl.go | 4 ++-- unix/syscall_hurd.go | 23 +++++++++++++++++++++++ unix/syscall_hurd_386.go | 29 +++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 unix/syscall_hurd.go create mode 100644 unix/syscall_hurd_386.go diff --git a/unix/gccgo.go b/unix/gccgo.go index 0dee23222..b06f52d74 100644 --- a/unix/gccgo.go +++ b/unix/gccgo.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build gccgo && !aix -// +build gccgo,!aix +//go:build gccgo && !aix && !hurd +// +build gccgo,!aix,!hurd package unix diff --git a/unix/gccgo_c.c b/unix/gccgo_c.c index 2cb1fefac..c4fce0e70 100644 --- a/unix/gccgo_c.c +++ b/unix/gccgo_c.c @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build gccgo -// +build !aix +// +build gccgo,!hurd +// +build !aix,!hurd #include #include diff --git a/unix/ioctl.go b/unix/ioctl.go index 6c7ad052e..1c51b0ec2 100644 --- a/unix/ioctl.go +++ b/unix/ioctl.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris -// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris +//go:build aix || darwin || dragonfly || freebsd || hurd || linux || netbsd || openbsd || solaris +// +build aix darwin dragonfly freebsd hurd linux netbsd openbsd solaris package unix diff --git a/unix/syscall_hurd.go b/unix/syscall_hurd.go new file mode 100644 index 000000000..93aa42085 --- /dev/null +++ b/unix/syscall_hurd.go @@ -0,0 +1,23 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build hurd +// +build hurd + +package unix + +/* +#include +int ioctl(int, unsigned long int, uintptr_t); +*/ +import "C" + +func ioctl(fd int, req uint, arg uintptr) (err error) { + r0, er := C.ioctl(C.int(fd), C.ulong(req), C.uintptr_t(arg)) + if r0 == -1 && er != nil { + err = er + } + return +} + diff --git a/unix/syscall_hurd_386.go b/unix/syscall_hurd_386.go new file mode 100644 index 000000000..44f3c4bb1 --- /dev/null +++ b/unix/syscall_hurd_386.go @@ -0,0 +1,29 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build 386 && hurd +// +build 386,hurd + +package unix + +const ( + TIOCGETA = 0x62251713 +) + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + +type Termios struct { + Iflag uint32 + Oflag uint32 + Cflag uint32 + Lflag uint32 + Cc [20]uint8 + Ispeed int32 + Ospeed int32 +}