Browse code

Cli binary can now be build on OpenBSD

Signed-off-by: Frank Groeneveld <frank@frankgroeneveld.nl>

Frank Groeneveld authored on 2016/03/18 22:53:19
Showing 4 changed files
... ...
@@ -1,4 +1,4 @@
1
-// +build linux freebsd darwin
1
+// +build linux freebsd darwin openbsd
2 2
 
3 3
 package layer
4 4
 
5 5
new file mode 100644
... ...
@@ -0,0 +1,15 @@
0
+package system
1
+
2
+import (
3
+	"syscall"
4
+)
5
+
6
+// fromStatT creates a system.StatT type from a syscall.Stat_t type
7
+func fromStatT(s *syscall.Stat_t) (*StatT, error) {
8
+	return &StatT{size: s.Size,
9
+		mode: uint32(s.Mode),
10
+		uid:  s.Uid,
11
+		gid:  s.Gid,
12
+		rdev: uint64(s.Rdev),
13
+		mtim: s.Mtim}, nil
14
+}
... ...
@@ -1,4 +1,4 @@
1
-// +build !linux,!windows,!freebsd,!solaris
1
+// +build !linux,!windows,!freebsd,!solaris,!openbsd
2 2
 
3 3
 package system
4 4
 
5 5
new file mode 100644
... ...
@@ -0,0 +1,69 @@
0
+package term
1
+
2
+import (
3
+	"syscall"
4
+	"unsafe"
5
+)
6
+
7
+const (
8
+	getTermios = syscall.TIOCGETA
9
+	setTermios = syscall.TIOCSETA
10
+)
11
+
12
+// Termios magic numbers, passthrough to the ones defined in syscall.
13
+const (
14
+	IGNBRK = syscall.IGNBRK
15
+	PARMRK = syscall.PARMRK
16
+	INLCR  = syscall.INLCR
17
+	IGNCR  = syscall.IGNCR
18
+	ECHONL = syscall.ECHONL
19
+	CSIZE  = syscall.CSIZE
20
+	ICRNL  = syscall.ICRNL
21
+	ISTRIP = syscall.ISTRIP
22
+	PARENB = syscall.PARENB
23
+	ECHO   = syscall.ECHO
24
+	ICANON = syscall.ICANON
25
+	ISIG   = syscall.ISIG
26
+	IXON   = syscall.IXON
27
+	BRKINT = syscall.BRKINT
28
+	INPCK  = syscall.INPCK
29
+	OPOST  = syscall.OPOST
30
+	CS8    = syscall.CS8
31
+	IEXTEN = syscall.IEXTEN
32
+)
33
+
34
+// Termios is the Unix API for terminal I/O.
35
+type Termios struct {
36
+	Iflag  uint32
37
+	Oflag  uint32
38
+	Cflag  uint32
39
+	Lflag  uint32
40
+	Cc     [20]byte
41
+	Ispeed uint32
42
+	Ospeed uint32
43
+}
44
+
45
+// MakeRaw put the terminal connected to the given file descriptor into raw
46
+// mode and returns the previous state of the terminal so that it can be
47
+// restored.
48
+func MakeRaw(fd uintptr) (*State, error) {
49
+	var oldState State
50
+	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(getTermios), uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
51
+		return nil, err
52
+	}
53
+
54
+	newState := oldState.termios
55
+	newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)
56
+	newState.Oflag &^= OPOST
57
+	newState.Lflag &^= (ECHO | ECHONL | ICANON | ISIG | IEXTEN)
58
+	newState.Cflag &^= (CSIZE | PARENB)
59
+	newState.Cflag |= CS8
60
+	newState.Cc[syscall.VMIN] = 1
61
+	newState.Cc[syscall.VTIME] = 0
62
+
63
+	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(setTermios), uintptr(unsafe.Pointer(&newState))); err != 0 {
64
+		return nil, err
65
+	}
66
+
67
+	return &oldState, nil
68
+}