File: pty_darwin.go

package info (click to toggle)
golang-github-rogpeppe-go-internal 1.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,184 kB
  • sloc: makefile: 6
file content (32 lines) | stat: -rw-r--r-- 786 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package pty

import (
	"bytes"
	"os"
	"syscall"
	"unsafe"
)

func ptyName(f *os.File) (string, error) {
	// Parameter length is encoded in the low 13 bits of the top word.
	// See https://github.com/apple/darwin-xnu/blob/2ff845c2e0/bsd/sys/ioccom.h#L69-L77
	const IOCPARM_MASK = 0x1fff
	const TIOCPTYGNAME_PARM_LEN = (syscall.TIOCPTYGNAME >> 16) & IOCPARM_MASK
	out := make([]byte, TIOCPTYGNAME_PARM_LEN)

	err := ioctl(f, "TIOCPTYGNAME", syscall.TIOCPTYGNAME, uintptr(unsafe.Pointer(&out[0])))
	if err != nil {
		return "", err
	}

	i := bytes.IndexByte(out, 0x00)
	return string(out[:i]), nil
}

func ptyGrant(f *os.File) error {
	return ioctl(f, "TIOCPTYGRANT", syscall.TIOCPTYGRANT, 0)
}

func ptyUnlock(f *os.File) error {
	return ioctl(f, "TIOCPTYUNLK", syscall.TIOCPTYUNLK, 0)
}