File: pty_darwin.go

package info (click to toggle)
golang-github-pkg-term 1.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 228 kB
  • sloc: makefile: 2
file content (36 lines) | stat: -rw-r--r-- 681 bytes parent folder | download | duplicates (3)
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
33
34
35
36
package termios

import (
	"errors"
	"unsafe"

	"golang.org/x/sys/unix"
)

func open_pty_master() (uintptr, error) {
	return open_device("/dev/ptmx")
}

func Ptsname(fd uintptr) (string, error) {
	n := make([]byte, _IOC_PARM_LEN(unix.TIOCPTYGNAME))

	err := ioctl(fd, unix.TIOCPTYGNAME, uintptr(unsafe.Pointer(&n[0])))
	if err != nil {
		return "", err
	}

	for i, c := range n {
		if c == 0 {
			return string(n[:i]), nil
		}
	}
	return "", errors.New("TIOCPTYGNAME string not NUL-terminated")
}

func grantpt(fd uintptr) error {
	return unix.IoctlSetInt(int(fd), unix.TIOCPTYGRANT, 0)
}

func unlockpt(fd uintptr) error {
	return unix.IoctlSetInt(int(fd), unix.TIOCPTYUNLK, 0)
}