...

Source file src/github.com/rogpeppe/go-internal/testscript/internal/pty/pty_darwin.go

Documentation: github.com/rogpeppe/go-internal/testscript/internal/pty

     1  package pty
     2  
     3  import (
     4  	"bytes"
     5  	"os"
     6  	"syscall"
     7  	"unsafe"
     8  )
     9  
    10  func ptyName(f *os.File) (string, error) {
    11  	// Parameter length is encoded in the low 13 bits of the top word.
    12  	// See https://github.com/apple/darwin-xnu/blob/2ff845c2e0/bsd/sys/ioccom.h#L69-L77
    13  	const IOCPARM_MASK = 0x1fff
    14  	const TIOCPTYGNAME_PARM_LEN = (syscall.TIOCPTYGNAME >> 16) & IOCPARM_MASK
    15  	out := make([]byte, TIOCPTYGNAME_PARM_LEN)
    16  
    17  	err := ioctl(f, "TIOCPTYGNAME", syscall.TIOCPTYGNAME, uintptr(unsafe.Pointer(&out[0])))
    18  	if err != nil {
    19  		return "", err
    20  	}
    21  
    22  	i := bytes.IndexByte(out, 0x00)
    23  	return string(out[:i]), nil
    24  }
    25  
    26  func ptyGrant(f *os.File) error {
    27  	return ioctl(f, "TIOCPTYGRANT", syscall.TIOCPTYGRANT, 0)
    28  }
    29  
    30  func ptyUnlock(f *os.File) error {
    31  	return ioctl(f, "TIOCPTYUNLK", syscall.TIOCPTYUNLK, 0)
    32  }
    33  

View as plain text