Commit 66b7b131 authored by Tobias Klauser's avatar Tobias Klauser Committed by Tobias Klauser

unix: add IoctlGetPtmget on netbsd

This ioctl is used to implement ptsname on netbsd.

Change-Id: Ic87f1bf7d15c6fbef0c2226a06a4983a504c3f30
Reviewed-on: https://go-review.googlesource.com/c/148097
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 3a766058
......@@ -65,6 +65,10 @@ func main() {
convertUtsnameRegex := regexp.MustCompile(`((Sys|Node|Domain)name|Release|Version|Machine)(\s+)\[(\d+)\]u?int8`)
b = convertUtsnameRegex.ReplaceAll(b, []byte("$1$3[$4]byte"))
// Convert [1024]int8 to [1024]byte in Ptmget members
convertPtmget := regexp.MustCompile(`([SC]n)(\s+)\[(\d+)\]u?int8`)
b = convertPtmget.ReplaceAll(b, []byte("$1[$3]byte"))
// Remove spare fields (e.g. in Statx_t)
spareFieldsRegex := regexp.MustCompile(`X__spare\S*`)
b = spareFieldsRegex.ReplaceAll(b, []byte("_"))
......
......@@ -13,6 +13,7 @@
package unix
import (
"runtime"
"syscall"
"unsafe"
)
......@@ -190,6 +191,13 @@ func IoctlGetTermios(fd int, req uint) (*Termios, error) {
return &value, err
}
func IoctlGetPtmget(fd int, req uint) (*Ptmget, error) {
var value Ptmget
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
runtime.KeepAlive(value)
return &value, err
}
func Uname(uname *Utsname) error {
mib := []_C_int{CTL_KERN, KERN_OSTYPE}
n := unsafe.Sizeof(uname.Sysname)
......
......@@ -5,6 +5,7 @@
package unix_test
import (
"bytes"
"testing"
"golang.org/x/sys/unix"
......@@ -33,3 +34,18 @@ func TestSysctlClockinfo(t *testing.T) {
t.Logf("tick = %v, tickadj = %v, hz = %v, profhz = %v, stathz = %v",
ci.Tick, ci.Tickadj, ci.Hz, ci.Profhz, ci.Stathz)
}
func TestIoctlPtmget(t *testing.T) {
fd, err := unix.Open("/dev/ptmx", unix.O_NOCTTY|unix.O_RDWR, 0666)
if err != nil {
t.Skip("failed to open /dev/ptmx, skipping test")
}
defer unix.Close(fd)
ptm, err := unix.IoctlGetPtmget(fd, unix.TIOCPTSNAME)
if err != nil {
t.Fatalf("IoctlGetPtmget: %v\n", err)
}
t.Logf("sfd = %v, ptsname = %v", ptm.Sfd, string(ptm.Sn[:bytes.IndexByte(ptm.Sn[:], 0)]))
}
......@@ -248,6 +248,8 @@ type Termios C.struct_termios
type Winsize C.struct_winsize
type Ptmget C.struct_ptmget
// fchmodat-like syscalls.
const (
......
......@@ -402,6 +402,13 @@ type Winsize struct {
Ypixel uint16
}
type Ptmget struct {
Cfd int32
Sfd int32
Cn [1024]byte
Sn [1024]byte
}
const (
AT_FDCWD = -0x64
AT_SYMLINK_NOFOLLOW = 0x200
......
......@@ -409,6 +409,13 @@ type Winsize struct {
Ypixel uint16
}
type Ptmget struct {
Cfd int32
Sfd int32
Cn [1024]byte
Sn [1024]byte
}
const (
AT_FDCWD = -0x64
AT_SYMLINK_NOFOLLOW = 0x200
......
......@@ -407,6 +407,13 @@ type Winsize struct {
Ypixel uint16
}
type Ptmget struct {
Cfd int32
Sfd int32
Cn [1024]byte
Sn [1024]byte
}
const (
AT_FDCWD = -0x64
AT_SYMLINK_NOFOLLOW = 0x200
......
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