Browse code

Remove cgo from term

Guillaume J. Charmes authored on 2013/06/02 07:51:45
Showing 2 changed files
... ...
@@ -8,13 +8,13 @@ import (
8 8
 )
9 9
 
10 10
 type Termios struct {
11
-	Iflag  uintptr
12
-	Oflag  uintptr
13
-	Cflag  uintptr
14
-	Lflag  uintptr
11
+	Iflag  uint32
12
+	Oflag  uint32
13
+	Cflag  uint32
14
+	Lflag  uint32
15 15
 	Cc     [20]byte
16
-	Ispeed uintptr
17
-	Ospeed uintptr
16
+	Ispeed uint32
17
+	Ospeed uint32
18 18
 }
19 19
 
20 20
 const (
... ...
@@ -5,26 +5,6 @@ import (
5 5
 	"unsafe"
6 6
 )
7 7
 
8
-// #include <termios.h>
9
-// #include <sys/ioctl.h>
10
-/*
11
-void MakeRaw(int fd) {
12
-  struct termios t;
13
-
14
-  // FIXME: Handle errors?
15
-  ioctl(fd, TCGETS, &t);
16
-
17
-  t.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
18
-  t.c_oflag &= ~OPOST;
19
-  t.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
20
-  t.c_cflag &= ~(CSIZE | PARENB);
21
-  t.c_cflag |= CS8;
22
-
23
-  ioctl(fd, TCSETS, &t);
24
-}
25
-*/
26
-import "C"
27
-
28 8
 const (
29 9
 	getTermios = syscall.TCGETS
30 10
 	setTermios = syscall.TCSETS
... ...
@@ -35,24 +15,20 @@ const (
35 35
 // restored.
36 36
 func MakeRaw(fd int) (*State, error) {
37 37
 	var oldState State
38
-	if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), syscall.TCGETS, uintptr(unsafe.Pointer(&oldState.termios)), 0, 0, 0); err != 0 {
38
+	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 {
39 39
 		return nil, err
40 40
 	}
41
-	C.MakeRaw(C.int(fd))
42
-	return &oldState, nil
43
-
44
-	// FIXME: post on goland issues this: very same as the C function bug non-working
45 41
 
46
-	// newState := oldState.termios
42
+	newState := oldState.termios
47 43
 
48
-	// newState.Iflag &^= (IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON)
49
-	// newState.Oflag &^= OPOST
50
-	// newState.Lflag &^= (ECHO | syscall.ECHONL | ICANON | ISIG | IEXTEN)
51
-	// newState.Cflag &^= (CSIZE | syscall.PARENB)
52
-	// newState.Cflag |= CS8
44
+	newState.Iflag &^= (syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK | syscall.ISTRIP | syscall.INLCR | syscall.IGNCR | syscall.ICRNL | syscall.IXON)
45
+	newState.Oflag &^= syscall.OPOST
46
+	newState.Lflag &^= (syscall.ECHO | syscall.ECHONL | syscall.ICANON | syscall.ISIG | syscall.IEXTEN)
47
+	newState.Cflag &^= (syscall.CSIZE | syscall.PARENB)
48
+	newState.Cflag |= syscall.CS8
53 49
 
54
-	// if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), syscall.TCSETS, uintptr(unsafe.Pointer(&newState))); err != 0 {
55
-	// 	return nil, err
56
-	// }
57
-	// return &oldState, nil
50
+	if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), setTermios, uintptr(unsafe.Pointer(&newState))); err != 0 {
51
+		return nil, err
52
+	}
53
+	return &oldState, nil
58 54
 }