17 BRKINT = tcflag_t (0000002)
18 ICRNL = tcflag_t (0000400)
19 INPCK = tcflag_t (0000020)
20 ISTRIP = tcflag_t (0000040)
21 IXON = tcflag_t (0002000)
22 OPOST = tcflag_t (0000001)
23 CS8 = tcflag_t (0000060)
24 ECHO = tcflag_t (0000010)
25 ICANON = tcflag_t (0000002)
26 IEXTEN = tcflag_t (0100000)
27 ISIG = tcflag_t (0000001)
33 B0 = speed_t(0000000) /* hang up */
34 B50 = speed_t(0000001)
35 B75 = speed_t(0000002)
36 B110 = speed_t(0000003)
37 B134 = speed_t(0000004)
38 B150 = speed_t(0000005)
39 B200 = speed_t(0000006)
40 B300 = speed_t(0000007)
41 B600 = speed_t(0000010)
42 B1200 = speed_t(0000011)
43 B1800 = speed_t(0000012)
44 B2400 = speed_t(0000013)
45 B4800 = speed_t(0000014)
46 B9600 = speed_t(0000015)
47 B19200 = speed_t(0000016)
48 B38400 = speed_t(0000017)
49 B57600 = speed_t(0010001)
50 B115200 = speed_t(0010002)
51 B230400 = speed_t(0010003)
52 B460800 = speed_t(0010004)
53 B500000 = speed_t(0010005)
54 B576000 = speed_t(0010006)
55 B921600 = speed_t(0010007)
56 B1000000 = speed_t(0010010)
57 B1152000 = speed_t(0010011)
58 B1500000 = speed_t(0010012)
59 B2000000 = speed_t(0010013)
60 B2500000 = speed_t(0010014)
61 B3000000 = speed_t(0010015)
62 B3500000 = speed_t(0010016)
63 B4000000 = speed_t(0010017)
68 c_iflag, c_oflag, c_cflag, c_lflag tcflag_t;
71 c_ispeed, c_ospeed speed_t
82 ttyfd uintptr = 0 // STDIN_FILENO
85 func Ttyfd(fd uintptr) {
89 func getTermios (dst *termios) error {
90 r1, _, errno := syscall.Syscall (syscall.SYS_IOCTL,
91 uintptr (ttyfd), uintptr (TCGETS),
92 uintptr (unsafe.Pointer (dst)));
94 if err := os.NewSyscallError ("SYS_IOCTL", errno); errno!=0 && err != nil {
99 // return errors.New("Error")
104 func setTermios (src *termios) error {
105 r1, _, errno := syscall.Syscall (syscall.SYS_IOCTL,
106 uintptr (ttyfd), uintptr (TCSETS),
107 uintptr (unsafe.Pointer (src)));
109 if err := os.NewSyscallError ("SYS_IOCTL", errno); errno!=0 &&err != nil {
114 return errors.New ("Error during ioctl tcsets syscall")
119 func SetRaw () (error) {
120 if err := getTermios (&orig_termios); err != nil { return err}
122 orig_termios.c_iflag &= ^(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
123 orig_termios.c_oflag &= ^(OPOST);
124 orig_termios.c_cflag |= (CS8);
125 orig_termios.c_lflag &= ^(ECHO | ICANON | IEXTEN | ISIG);
127 orig_termios.c_cc[VMIN] = 1;
128 orig_termios.c_cc[VTIME] = 0;
130 return setTermios(&orig_termios)
133 func SetSpeed (speed speed_t) (error) {
134 if err := getTermios (&orig_termios); err != nil { return err }
135 orig_termios.c_ispeed = speed
136 orig_termios.c_ospeed = speed
137 return setTermios(&orig_termios)