Skip to content

Commit

Permalink
Merge pull request containerd#9 from justincormack/no-cgo
Browse files Browse the repository at this point in the history
Remove use of cgo
  • Loading branch information
crosbymichael authored May 24, 2017
2 parents d39a644 + b047552 commit e0a2cdc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
7 changes: 2 additions & 5 deletions console_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

package console

// #include <termios.h>
import "C"

import (
"os"
"unsafe"
Expand Down Expand Up @@ -91,8 +88,8 @@ func (m *master) SetRaw() error {
if err != nil {
return err
}
C.cfmakeraw((*C.struct_termios)(unsafe.Pointer(&rawState)))
rawState.Oflag = rawState.Oflag | C.OPOST
rawState = cfmakeraw(rawState)
rawState.Oflag = rawState.Oflag | unix.OPOST
return tcset(m.f.Fd(), &rawState)
}

Expand Down
12 changes: 12 additions & 0 deletions tc_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,15 @@ func saneTerminal(f *os.File) error {
termios.Oflag &^= unix.ONLCR
return tcset(f.Fd(), &termios)
}

func cfmakeraw(t unix.Termios) unix.Termios {
t.Iflag = uint64(uint32(t.Iflag) & ^uint32((unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON)))
t.Oflag = uint64(uint32(t.Oflag) & ^uint32(unix.OPOST))
t.Lflag = uint64(uint32(t.Lflag) & ^(uint32(unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN)))
t.Cflag = uint64(uint32(t.Cflag) & ^(uint32(unix.CSIZE | unix.PARENB)))
t.Cflag = t.Cflag | unix.CS8
t.Cc[unix.VMIN] = 1
t.Cc[unix.VTIME] = 0

return t
}
12 changes: 12 additions & 0 deletions tc_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,15 @@ func saneTerminal(f *os.File) error {
termios.Oflag &^= unix.ONLCR
return tcset(f.Fd(), &termios)
}

func cfmakeraw(t unix.Termios) unix.Termios {
t.Iflag = t.Iflag & ^uint32((unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON))
t.Oflag = t.Oflag & ^uint32(unix.OPOST)
t.Lflag = t.Lflag & ^(uint32(unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN))
t.Cflag = t.Cflag & ^(uint32(unix.CSIZE | unix.PARENB))
t.Cflag = t.Cflag | unix.CS8
t.Cc[unix.VMIN] = 1
t.Cc[unix.VTIME] = 0

return t
}
12 changes: 12 additions & 0 deletions tc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,15 @@ func saneTerminal(f *os.File) error {
termios.Oflag &^= unix.ONLCR
return tcset(f.Fd(), &termios)
}

func cfmakeraw(t unix.Termios) unix.Termios {
t.Iflag = t.Iflag & ^uint32((unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON))
t.Oflag = t.Oflag & ^uint32(unix.OPOST)
t.Lflag = t.Lflag & ^(uint32(unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN))
t.Cflag = t.Cflag & ^(uint32(unix.CSIZE | unix.PARENB))
t.Cflag = t.Cflag | unix.CS8
t.Cc[unix.VMIN] = 1
t.Cc[unix.VTIME] = 0

return t
}

0 comments on commit e0a2cdc

Please sign in to comment.