Browse code

Update vendor for kr/pty

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume.charmes@docker.com> (github: creack)

Guillaume J. Charmes authored on 2014/03/11 05:21:30
Showing 3 changed files
... ...
@@ -2,9 +2,14 @@
2 2
 package pty
3 3
 
4 4
 import (
5
+	"errors"
5 6
 	"os"
6 7
 )
7 8
 
9
+// ErrUnsupported is returned if a function is not
10
+// available on the current platform.
11
+var ErrUnsupported = errors.New("unsupported")
12
+
8 13
 // Opens a pty and its corresponding tty.
9 14
 func Open() (pty, tty *os.File, err error) {
10 15
 	return open()
11 16
new file mode 100644
... ...
@@ -0,0 +1,53 @@
0
+package pty
1
+
2
+import (
3
+	"os"
4
+	"strconv"
5
+	"syscall"
6
+	"unsafe"
7
+)
8
+
9
+const (
10
+	sys_TIOCGPTN   = 0x4004740F
11
+	sys_TIOCSPTLCK = 0x40045431
12
+)
13
+
14
+func open() (pty, tty *os.File, err error) {
15
+	p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
16
+	if err != nil {
17
+		return nil, nil, err
18
+	}
19
+
20
+	sname, err := ptsname(p)
21
+	if err != nil {
22
+		return nil, nil, err
23
+	}
24
+
25
+	t, err := os.OpenFile(sname, os.O_RDWR|syscall.O_NOCTTY, 0)
26
+	if err != nil {
27
+		return nil, nil, err
28
+	}
29
+	return p, t, nil
30
+}
31
+
32
+func ptsname(f *os.File) (string, error) {
33
+	var n int
34
+	err := ioctl(f.Fd(), sys_TIOCGPTN, &n)
35
+	if err != nil {
36
+		return "", err
37
+	}
38
+	return "/dev/pts/" + strconv.Itoa(n), nil
39
+}
40
+
41
+func ioctl(fd uintptr, cmd uintptr, data *int) error {
42
+	_, _, e := syscall.Syscall(
43
+		syscall.SYS_IOCTL,
44
+		fd,
45
+		cmd,
46
+		uintptr(unsafe.Pointer(data)),
47
+	)
48
+	if e != 0 {
49
+		return syscall.ENOTTY
50
+	}
51
+	return nil
52
+}
0 53
new file mode 100644
... ...
@@ -0,0 +1,27 @@
0
+// +build !linux,!darwin,!freebsd
1
+
2
+package pty
3
+
4
+import (
5
+	"os"
6
+)
7
+
8
+func open() (pty, tty *os.File, err error) {
9
+	return nil, nil, ErrUnsupported
10
+}
11
+
12
+func ptsname(f *os.File) (string, error) {
13
+	return "", ErrUnsupported
14
+}
15
+
16
+func grantpt(f *os.File) error {
17
+	return ErrUnsupported
18
+}
19
+
20
+func unlockpt(f *os.File) error {
21
+	return ErrUnsupported
22
+}
23
+
24
+func ioctl(fd, cmd, ptr uintptr) error {
25
+	return ErrUnsupported
26
+}