1//go:build openbsd 2//+build openbsd 3 4package pty 5 6import ( 7 "os" 8 "syscall" 9 "unsafe" 10) 11 12func open() (pty, tty *os.File, err error) { 13 /* 14 * from ptm(4): 15 * The PTMGET command allocates a free pseudo terminal, changes its 16 * ownership to the caller, revokes the access privileges for all previous 17 * users, opens the file descriptors for the pty and tty devices and 18 * returns them to the caller in struct ptmget. 19 */ 20 21 p, err := os.OpenFile("/dev/ptm", os.O_RDWR|syscall.O_CLOEXEC, 0) 22 if err != nil { 23 return nil, nil, err 24 } 25 defer p.Close() 26 27 var ptm ptmget 28 if err := ioctl(p.Fd(), uintptr(ioctl_PTMGET), uintptr(unsafe.Pointer(&ptm))); err != nil { 29 return nil, nil, err 30 } 31 32 pty = os.NewFile(uintptr(ptm.Cfd), "/dev/ptm") 33 tty = os.NewFile(uintptr(ptm.Sfd), "/dev/ptm") 34 35 return pty, tty, nil 36} 37